Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/resources/src/lib/graphics/importer/texture_sequence.cc @ 7914

Last change on this file since 7914 was 7221, checked in by bensch, 19 years ago

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

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 std::string& imageName)
127{
128  SDL_Surface* addSurface = IMG_Load(imageName.c_str());
129  bool success = this->addFrame(addSurface);
130  delete addSurface;
131
132  return success;
133}
134
135/**
136 * @brief adds a new Frame at the end of the Sequence.
137 * @param surface the Surface to add at the end of the Sequence.
138 */
139bool TextureSequence::addFrame(SDL_Surface* surface)
140{
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);
151
152  return true;
153}
154
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);
164
165  return true;
166}
167
168/**
169 * @brief moves to the n'th texture which can then be retrieved via the Texture function: this->getTexture()
170 * @param frameNumber the n-th frame
171 */
172/*void TextureSequence::gotoFrame(unsigned int frameNumber)
173{
174  if (this->textures.size() > frameNumber)
175    this->setTexture(this->textures[frameNumber]);
176}
177*/
Note: See TracBrowser for help on using the repository browser.