Loading TGA files to openGL Textures

Nibbie
Posts: 1
Joined: 2010.11
Post: #16
It still has the same problem. Does anything in tga.c need to be modified too?
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2010.11
Post: #17
For some strange reason it shows only the last texture loaded Huh
For example if I do this:

PHP Code:
TextureImage myTexture;
TextureImage myTexture2;

LoadTGA(&myTexture"/Data/GFX/opening.tga");
CreateTexture(&myTexture0);
LoadTGA(&myTexture"/Data/GFX/loading.tga");
CreateTexture(&myTexture20);

glEnable(GL_TEXTURE_2D);
    
glBegin(GL_QUADS);
        
glColor4f(1.0,1.0,1.0,1.0);
        
glBindTexture(GL_TEXTURE_2DmyTexture.texID);
        
glTexCoord2f(0.00.0);
        
glVertex2f(  0.0f,   -128.0f);
        
glTexCoord2f(1.00.0);
        
glVertex2f(1024.0f,   -128.0f);
        
glTexCoord2f(1.01.0);
        
glVertex2f(1024.0f896.0f);
        
glTexCoord2f(0.01.0);
        
glVertex2f(  0.0f896.0f);
    
glEnd();
glDisable(GL_TEXTURE_2D); 

This draws the most recent texture loaded (loading.tga), instead of the textyre specified (myTexture/opening.tga). Is there any obvious reason why?
Quote this message in a reply
kberg
Unregistered
 
Post: #18
Joseph Duchesne Wrote:
Code:
TextureImage myTexture;
TextureImage myTexture2;

LoadTGA(&myTexture, "/Data/GFX/opening.tga");
CreateTexture(&myTexture, 0);
LoadTGA(&myTexture, "/Data/GFX/loading.tga");
CreateTexture(&myTexture2, 0);
This draws the most recent texture loaded (loading.tga), instead of the texture specified (myTexture/opening.tga). Is there any obvious reason why?

Yeah, you want to change
LoadTGA(&myTexture, "/Data/GFX/loading.tga"); to
LoadTGA(&myTexture2, "/Data/GFX/loading.tga");

The way the tga loader works is it loads in the file into an image buffer (a large array of bytes in RGB or ARGB order). When you call CreateTexture, it uploads the data from that image buffer to OpenGL to make a texture from it. It stores an index to that texture in the TextureImage struct as well, so you need one unique TextureImage instance per image you want to use.
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2010.11
Post: #19
strangely, even when I changed it it still didn't work.

Code:
TextureImage myTexture;
TextureImage myTexture2;

    LoadTGA(&myTexture, "/Data/GFX/opening.tga");
    CreateTexture(&myTexture, 0);
    LoadTGA(&myTexture2, "/Data/GFX/loading.tga");
    CreateTexture(&myTexture2, 0);

    glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
        glColor4f(1.0,1.0,1.0,1.0);
        glBindTexture(GL_TEXTURE_2D, myTexture.texID); //even if I delete this line it shows myTexture2, not 1.
        glTexCoord2f(0.0, 0.0);

It shows the most recently loaded texture instead of the one I want. Has anyone else had similar problems?
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #20
Joseph Duchesne Wrote:It shows the most recently loaded texture instead of the one I want. Has anyone else had similar problems?
You can't use glBindTexture() within a glBegin()/glEnd() block. Move it to before glBegin().

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2010.11
Post: #21
Thanks, that wasn't in the manual Wink . (it [probably was, I just never saw it)
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #22
kberg (or anyone) what is the extension .cc? I'm used to .h, .c, .cpp, .hpp but not .cc.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #23
man glBindTexture:

GL_INVALID_OPERATION is generated if glBindTexture is executed between
the execution of glBegin and the corresponding execution of glEnd.

glGetError() will catch all these sort of problems for you.
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #24
SimReality/Nick Wrote:kberg (or anyone) what is the extension .cc? I'm used to .h, .c, .cpp, .hpp but not .cc.
It's just another C++ extension. I've also seen ".cp" and ".C" used for C++ (the latter obviously only works on case-sensitive filesystems!).

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenAL - Ogg files vs Caf files Fred9000 8 14,308 Aug 23, 2011 08:01 PM
Last Post: ipeku
  [SOLVED]OpenGL edges of textures mk12 2 4,461 Sep 2, 2010 08:07 PM
Last Post: mk12
  OpenGL ES Loading images techy 4 3,911 Dec 24, 2009 02:01 PM
Last Post: techy
  OpenGL Image Textures mikey 52 25,031 Jun 30, 2009 10:42 AM
Last Post: AnotherJake
  Dealing with inverted textures in OpenGL johncmurphy 7 7,109 Jun 15, 2009 08:11 AM
Last Post: Skorche