Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/avi_play/src/lib/graphics/importer/texture_sequence.cc @ 6339

Last change on this file since 6339 was 6339, checked in by hdavid, 18 years ago

branches\avi_play: some copy, pasta & delete

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{
[5863]49  // delete all images
50  while(!this->images.empty())
51  {
52    SDL_FreeSurface(this->images.back());
53    this->images.pop_back();
54  }
55
[5865]56  this->setTexture(0);
[5863]57  // delete all textures.
58  while(!this->textures.empty())
59  {
60    if (glIsTexture(this->textures.back()))
61      glDeleteTextures(1, &this->textures.back());
62    this->textures.pop_back();
63  }
[3344]64}
65
[3905]66
[5860]67/**
[5865]68 * @brief rebuilds all the textures from the Images stored in this FrameSequence
[5860]69 */
[5861]70bool TextureSequence::rebuild()
[5754]71{
[5863]72  PRINTF(3)("Reloading TextureSequence of %s '%s'\n", this->getClassName(), this->getName());
[5754]73
[5863]74  for (unsigned int i = 0; i < this->textures.size(); i++)
75  {
76    if (glIsTexture(this->textures[i]))
77    {
78      glDeleteTextures(1, &this->textures[i]);
79      this->textures[i] = 0;
80    }
81
82    if (this->images[i] != NULL)
83      this->textures[i] = loadTexToGL(this->images[i]);
84  }
[5754]85}
[5860]86
[5863]87/**
[5865]88 * @brief loads an image Sequence
[5863]89 * @param count how many images to load to the TextureSequence
90 * @param ... the names of the Images to load
91 * @returns true on success, false otherwise
92 */
[5861]93bool TextureSequence::loadImageSeries(unsigned int count, ...)
[5860]94{
95  va_list textureNameList;
96  va_start(textureNameList, count);
97
[5863]98  return this->loadImageSeries(count, textureNameList);
[5860]99}
100
[5863]101/**
[5865]102 * @brief loads an image Sequence
[5863]103 * @param count how many images to load to the TextureSequence
104 * @param textures the names of the Images to load
105 * @returns true on success, false otherwise
106 */
[5861]107bool TextureSequence::loadImageSeries(unsigned int count, va_list textures)
[5860]108{
[5863]109  bool retVal = true;
110  for (unsigned int i = 0; i < count; i++)
111  {
112    if( !this->addFrame(va_arg(textures, char*)))
113      retVal = false;
114  }
115  return retVal;
[5860]116}
117
[5865]118/**
119 * @brief adds a new Frame to this Sequence (at the end)
120 * @param imageName the Name of the Image to add
121 * @returns true on success
122 */
[5861]123bool TextureSequence::addFrame(const char* imageName)
[5860]124{
[5863]125  if (imageName == NULL)
126    return false;
[5860]127
[5863]128  SDL_Surface* addSurface = IMG_Load(imageName);
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);
[6149]151
[5865]152  return true;
[5860]153}
[5865]154
[6094]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{
[6112]161  if (texture == 0)
[6094]162    return false;
163  this->textures.push_back(texture);
[6112]164
[6094]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 */
[6339]172/*void TextureSequence::gotoFrame(unsigned int frameNumber)
[5865]173{
174  if (this->textures.size() > frameNumber)
175    this->setTexture(this->textures[frameNumber]);
176}
[6339]177*/
Note: See TracBrowser for help on using the repository browser.