Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/texture_data.cc @ 10727

Last change on this file since 10727 was 10460, checked in by patrick, 18 years ago

some texture attributes, camera target fix

File size: 2.4 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.h"
19
20#include "debug.h"
21#include "compiler.h"
22
23
24/**
25 * @brief creates a new Texture Data.
26 */
27TextureData::TextureData()
28{
29  this->bAlpha = false;
30  this->texture = 0;
31  this->image = NULL;
32  this->height = 0.;
33  this->width = 0.;
34}
35
36
37/**
38 * @brief Destructor of a Texture
39 *
40 *  Frees Data, and deletes the textures from GL
41 */
42TextureData::~TextureData()
43{
44  if (this->texture != 0)
45    glDeleteTextures(1, &this->texture);
46  if (this->image != NULL)
47    SDL_FreeSurface(this->image);
48}
49
50
51/**
52 * @brief Loads an SDL_Surface.
53 * @param surface the Surface to Load.
54 * @param target the GL-Target to load the Surface to default GL_TEXTURE_2D
55 * @returns true on success, false otherwise.
56 */
57bool TextureData::loadSurface(SDL_Surface* surface, GLenum target)
58{
59  if( surface != NULL)
60  {
61    this->height = surface->h;
62    this->width = surface->w;
63  }
64
65  if (Texture::getTextureEnableState())
66  {
67    SDL_Surface* newSurf = Texture::prepareSurface(surface, this->bAlpha);
68    if (newSurf != NULL)
69    {
70      this->setSurface(newSurf);
71      this->setTexture(Texture::loadTexToGL(newSurf, target));
72      return true;
73    }
74  }
75  return false;
76}
77
78
79
80/**
81 * @brief set the surface this Texture handles
82 * @param newSurface the new Surface to set as the image for this Texture.
83 * @returns true on success.
84 *
85 * This deletes the old version of the stored Texture,
86 * and sets the newly given Surface as current.
87 */
88bool TextureData::setSurface(SDL_Surface* newSurface)
89{
90  if (this->image != NULL)
91    SDL_FreeSurface(this->image);
92
93  this->image = newSurface;
94
95  return (this->image != NULL);
96}
97
98
99/**
100 * @brief sets a new Texture to the Data.
101 * @param texture the Texture
102 * @returns true on success.
103 */
104bool TextureData::setTexture(GLuint texture)
105{
106     // unload the old Texture.
107  if (this->texture != 0 && glIsTexture(this->getTexture()))
108  {
109    glDeleteTextures(1, &this->texture);
110  }
111  this->texture = texture;
112  return (texture != 0);
113}
Note: See TracBrowser for help on using the repository browser.