Initial revision
[0ad:0ad.git] / terrain / bak / 0 / OGLTexture.cpp
1 //***********************************************************
2 //
3 // Name:                OGLTexture.Cpp
4 // Last Update: 14/2/02
5 // Author:              Poya Manouchehri
6 //
7 // Description: This class represents a OpenGL Texture.
8 //                              When a CTexture gets registered with the
9 //                              renderer, one of these is created and added
10 //                              to the renderer's list of registered textures
11 //
12 //***********************************************************
13
14 #include "OGLTexture.H"
15
16 COGLTexture::COGLTexture ()
17 {
18         m_TextureID = 0;
19         m_pTextureBK = NULL;
20 }
21
22 COGLTexture::~COGLTexture ()
23 {
24         glDeleteTextures (1, &m_TextureID);
25         m_pTextureBK = NULL;
26 }
27
28 FRESULT COGLTexture::CreateTexture (CTexture *texture)
29 {
30 //      unsigned int *NewBits;
31
32         //create and set the texture name
33         glGenTextures (1, &m_TextureID);
34         glBindTexture (GL_TEXTURE_2D, m_TextureID);
35
36         if (!texture->GetMipMapFlag ())
37         {
38 //              NewBits = new unsigned int [texture->GetWidth()*texture->GetHeight()];
39                 
40                 //resize the image for the next mip level
41 //              if (gluScaleImage (GL_RGBA,
42 //                                                 texture->GetWidth (),
43 //                                                 texture->GetHeight (),
44 //                                                 GL_UNSIGNED_INT,
45 //                                                 texture->GetBits (),
46 //                                                 texture->GetWidth (),
47 //                                                 texture->GetHeight (),
48 //                                                 GL_UNSIGNED_INT,
49 //                                                 NewBits) != 0)
50 //                      return R_FAIL;
51
52                 //create the texture
53                 glTexImage2D (GL_TEXTURE_2D,
54                                           0,
55                                           4,
56                                           texture->GetWidth (),
57                                           texture->GetHeight (),
58                                           0,
59                                           GL_RGBA,
60                                           GL_UNSIGNED_BYTE,
61                                           texture->GetBits());
62                 
63 //              if (NewBits)
64 //                      delete [] NewBits;
65         }
66         else
67         {
68                 //build full mipmap table
69                 if (gluBuild2DMipmaps (GL_TEXTURE_2D,
70                                                            4,
71                                                            texture->GetWidth (),
72                                                            texture->GetHeight (),
73                                                            GL_RGBA,
74                                                            GL_UNSIGNED_BYTE,
75                                                            texture->GetBits()) != 0)
76                         return R_FAIL;
77         }
78
79         m_pTextureBK = texture;
80
81         return R_OK;
82 }