Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Some missing stuff

File size: 4.1 KB
Line 
1/*
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
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
17
18#include "texture_sequence.h"
19
20#include "debug.h"
21#include "graphics_engine.h"
22
23#ifdef HAVE_SDL_IMAGE_H
24#include <SDL_image.h>
25#else
26#include <SDL/SDL_image.h>
27#endif
28
29/**
30 *  Constructor for a Texture
31 */
32TextureSequence::TextureSequence(unsigned int count, ...)
33{
34  this->setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");
35
36  va_list textureNameList;
37  va_start(textureNameList, count);
38
39  this->loadImageSeries(count, textureNameList);
40}
41
42/**
43 * Destructor of a TextureSequence
44 *
45 * Frees Data, and deletes the textures from GL
46 */
47TextureSequence::~TextureSequence()
48{
49  this->clearLists();
50}
51
52void TextureSequence::clearLists()
53{
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  }
68}
69
70/**
71 * @brief rebuilds all the textures from the Images stored in this FrameSequence
72 */
73bool TextureSequence::rebuild()
74{
75  PRINTF(3)("Reloading TextureSequence of %s '%s'\n", this->getClassName(), this->getName());
76
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  }
88}
89
90/**
91 * @brief loads an image Sequence
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 */
96bool TextureSequence::loadImageSeries(unsigned int count, ...)
97{
98  va_list textureNameList;
99  va_start(textureNameList, count);
100
101  return this->loadImageSeries(count, textureNameList);
102}
103
104/**
105 * @brief loads an image Sequence
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 */
110bool TextureSequence::loadImageSeries(unsigned int count, va_list textures)
111{
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;
119}
120
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 */
126bool TextureSequence::addFrame(const char* imageName)
127{
128  if (imageName == NULL)
129    return false;
130
131  SDL_Surface* addSurface = IMG_Load(imageName);
132  bool success = this->addFrame(addSurface);
133  delete addSurface;
134
135  return success;
136}
137
138/**
139 * @brief adds a new Frame at the end of the Sequence.
140 * @param surface the Surface to add at the end of the Sequence.
141 */
142bool TextureSequence::addFrame(SDL_Surface* surface)
143{
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);
154
155  return true;
156}
157
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);
167
168  return true;
169}
170
171/**
172 * @brief moves to the n'th texture which can then be retrieved via the Texture function: this->getTexture()
173 * @param frameNumber the n-th frame
174 */
175/*void TextureSequence::gotoFrame(unsigned int frameNumber)
176{
177  if (this->textures.size() > frameNumber)
178    this->setTexture(this->textures[frameNumber]);
179}
180*/
Note: See TracBrowser for help on using the repository browser.