Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/std/src/lib/graphics/importer/texture_sequence.cc @ 7218

Last change on this file since 7218 was 7218, checked in by bensch, 18 years ago

orxonox/std:: more strings

File size: 4.1 KB
RevLine 
[4662]1/*
[3341]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
[3590]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
17
[5861]18#include "texture_sequence.h"
[3341]19
[4357]20#include "debug.h"
[3622]21#include "graphics_engine.h"
22
[4662]23#ifdef HAVE_SDL_IMAGE_H
[4357]24#include <SDL_image.h>
[4662]25#else
26#include <SDL/SDL_image.h>
27#endif
[4357]28
[3341]29/**
[4836]30 *  Constructor for a Texture
[5865]31 */
[5861]32TextureSequence::TextureSequence(unsigned int count, ...)
[3655]33{
[5861]34  this->setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");
[5304]35
[5860]36  va_list textureNameList;
37  va_start(textureNameList, count);
38
39  this->loadImageSeries(count, textureNameList);
[4662]40}
[3655]41
42/**
[5865]43 * Destructor of a TextureSequence
44 *
45 * Frees Data, and deletes the textures from GL
46 */
[5861]47TextureSequence::~TextureSequence()
[3344]48{
[6532]49  this->clearLists();
50}
51
52void TextureSequence::clearLists()
53{
[5863]54  // delete all images
55  while(!this->images.empty())
56  {
57    SDL_FreeSurface(this->images.back());
58    this->images.pop_back();
59  }
60
61  // delete all textures.
62  while(!this->textures.empty())
63  {
64    if (glIsTexture(this->textures.back()))
65      glDeleteTextures(1, &this->textures.back());
66    this->textures.pop_back();
67  }
[3344]68}
69
[5860]70/**
[5865]71 * @brief rebuilds all the textures from the Images stored in this FrameSequence
[5860]72 */
[5861]73bool TextureSequence::rebuild()
[5754]74{
[5863]75  PRINTF(3)("Reloading TextureSequence of %s '%s'\n", this->getClassName(), this->getName());
[5754]76
[5863]77  for (unsigned int i = 0; i < this->textures.size(); i++)
78  {
79    if (glIsTexture(this->textures[i]))
80    {
81      glDeleteTextures(1, &this->textures[i]);
82      this->textures[i] = 0;
83    }
84
85    if (this->images[i] != NULL)
86      this->textures[i] = loadTexToGL(this->images[i]);
87  }
[5754]88}
[5860]89
[5863]90/**
[5865]91 * @brief loads an image Sequence
[5863]92 * @param count how many images to load to the TextureSequence
93 * @param ... the names of the Images to load
94 * @returns true on success, false otherwise
95 */
[5861]96bool TextureSequence::loadImageSeries(unsigned int count, ...)
[5860]97{
98  va_list textureNameList;
99  va_start(textureNameList, count);
100
[5863]101  return this->loadImageSeries(count, textureNameList);
[5860]102}
103
[5863]104/**
[5865]105 * @brief loads an image Sequence
[5863]106 * @param count how many images to load to the TextureSequence
107 * @param textures the names of the Images to load
108 * @returns true on success, false otherwise
109 */
[5861]110bool TextureSequence::loadImageSeries(unsigned int count, va_list textures)
[5860]111{
[5863]112  bool retVal = true;
113  for (unsigned int i = 0; i < count; i++)
114  {
115    if( !this->addFrame(va_arg(textures, char*)))
116      retVal = false;
117  }
118  return retVal;
[5860]119}
120
[5865]121/**
122 * @brief adds a new Frame to this Sequence (at the end)
123 * @param imageName the Name of the Image to add
124 * @returns true on success
125 */
[7218]126bool TextureSequence::addFrame(const std::string& imageName)
[5860]127{
[7218]128  SDL_Surface* addSurface = IMG_Load(imageName.c_str());
[5863]129  bool success = this->addFrame(addSurface);
130  delete addSurface;
[5860]131
[5863]132  return success;
[5860]133}
134
[5863]135/**
[5865]136 * @brief adds a new Frame at the end of the Sequence.
[5863]137 * @param surface the Surface to add at the end of the Sequence.
138 */
[5861]139bool TextureSequence::addFrame(SDL_Surface* surface)
[5860]140{
[5863]141  if (surface == NULL)
142    return false;
143  bool hasAlpha;
144  SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha);
145  if (newSurf != NULL)
146  {
147    this->images.push_back(newSurf);
148    this->textures.push_back(Texture::loadTexToGL(newSurf));
149  }
150  this->setAlpha(hasAlpha);
[6532]151
[5865]152  return true;
[5860]153}
[5865]154
[6532]155/**
156 * @brief adds a new Frame at the end of the Sequence.
157 * @param texture the texture to add at the end of the Sequence.
158 */
159bool TextureSequence::addFrame(GLuint texture)
160{
161  if (texture == 0)
162    return false;
163  this->textures.push_back(texture);
[5865]164
[6532]165  return true;
166}
[5865]167
168/**
[5885]169 * @brief moves to the n'th texture which can then be retrieved via the Texture function: this->getTexture()
[5865]170 * @param frameNumber the n-th frame
171 */
[6532]172/*void TextureSequence::gotoFrame(unsigned int frameNumber)
[5865]173{
174  if (this->textures.size() > frameNumber)
175    this->setTexture(this->textures[frameNumber]);
176}
[6624]177*/
Note: See TracBrowser for help on using the repository browser.