Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/texture_sequence.cc @ 6624

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

orxonox/trunk: Some missing stuff

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 */
[5861]126bool TextureSequence::addFrame(const char* imageName)
[5860]127{
[5863]128  if (imageName == NULL)
129    return false;
[5860]130
[5863]131  SDL_Surface* addSurface = IMG_Load(imageName);
132  bool success = this->addFrame(addSurface);
133  delete addSurface;
[5860]134
[5863]135  return success;
[5860]136}
137
[5863]138/**
[5865]139 * @brief adds a new Frame at the end of the Sequence.
[5863]140 * @param surface the Surface to add at the end of the Sequence.
141 */
[5861]142bool TextureSequence::addFrame(SDL_Surface* surface)
[5860]143{
[5863]144  if (surface == NULL)
145    return false;
146  bool hasAlpha;
147  SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha);
148  if (newSurf != NULL)
149  {
150    this->images.push_back(newSurf);
151    this->textures.push_back(Texture::loadTexToGL(newSurf));
152  }
153  this->setAlpha(hasAlpha);
[6532]154
[5865]155  return true;
[5860]156}
[5865]157
[6532]158/**
159 * @brief adds a new Frame at the end of the Sequence.
160 * @param texture the texture to add at the end of the Sequence.
161 */
162bool TextureSequence::addFrame(GLuint texture)
163{
164  if (texture == 0)
165    return false;
166  this->textures.push_back(texture);
[5865]167
[6532]168  return true;
169}
[5865]170
171/**
[5885]172 * @brief moves to the n'th texture which can then be retrieved via the Texture function: this->getTexture()
[5865]173 * @param frameNumber the n-th frame
174 */
[6532]175/*void TextureSequence::gotoFrame(unsigned int frameNumber)
[5865]176{
177  if (this->textures.size() > frameNumber)
178    this->setTexture(this->textures[frameNumber]);
179}
[6624]180*/
Note: See TracBrowser for help on using the repository browser.