Skip to main content
gamedev.net
🔒 Locked

OGL: Odd Texture Problem

Started by Galileo430 8 replies 200+ views
Original Post
Galileo430
Galileo430
In the intrest of speeding up texture loading, I developed my own file format/compileing tools for my current project. I am feeding the program Red, Green, Blue (RGB for short) componants. However, No matter what I do, I never get ANY colors other then Black and Red. I am sure all the rest of my code is bug free. All except for the code below. Here is the code.
    
if (ImportVTX(filename) == FALSE)
{
	return FALSE;
}
	
glGenTextures(1, &Texture[NumTextures]);
glBindTexture(GL_TEXTURE_2D, Texture[NumTextures]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, tex.imgsizex, tex.imgsizey, 0, GL_RGB, GL_UNSIGNED_BYTE, imgdata); //Heh, Loaded
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_REPEAT);
    
ImportVTX Loads the data into the "tex" structure. imgdata a string of unsigned bytes (r, g, b, r, g, b, r, g, b.... and so on...) I think it''s a error with glTexImage2D. This is not my area. Thanks, Steven
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Poontardis
Poontardis
I'm only guessing, but is NumTextures a #define as the total number of textures you use in your program?

If so, then you need to swap NumTextures, in the code snippet you posted, for the texture id you want for the current texture you're binding.

e.g.
        
for (int CurrentTexture = 0; CurrentTexture < NumTextures; CurrentTexture++)
{
filename = GenerateTextureFilename(CurrentTexture);

if (ImportVTX(filename) == FALSE)
{
return FALSE;
}

glGenTextures(1, &Texture[CurrentTexture]);

glBindTexture(GL_TEXTURE_2D, Texture[CurrentTexture]);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_REPEAT);

glTexImage2D(GL_TEXTURE_2D, 0, 3, tex.imgsizex, tex.imgsizey, 0, GL_RGB, GL_UNSIGNED_BYTE, imgdata);
}


or something like that if you catch my drift...

..of course it's entirely possible that I've missed the point completely and this post if useless

Hope this helps. If not then post more code/flame me/wait for someone more knowledgeable to post*

Laters, Barry.

* delete as applicable

Edited by - poontardis on October 25, 2000 9:11:38 AM
Galileo430
Galileo430
numtextures is a int used to define a texture array. So I can load all the textures at the beginning of a level instead of loading as I go.

The problem is my bitmaps come out looking like if you put GL_RED in instead of GL_RGB.

Does anyone know what the exact squence of pixels should be for a RGB texure? It should be R, G, B right?

If I give the program a texture that is totaly blue(00, 00, FF). I get Black. I give it white (00, 00, 00). I get light red. What makes things worse is if I change the border I get nothing BUT red.

It''s driveing me nuts!
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Galileo430
Galileo430
Here is the more refined source.

    
GLuint Texture[65535];
short NumTextures;
VTXDATA tex;
GLuint *imgdata;

BOOL LoadTexture(char *filename)
{

//---------------------------\\

// Texture Loader \\

//---------------------------\\


if (ImportVTX(filename) == FALSE)
{
//AH!!AH!

return FALSE;
}

glGenTextures(1, &Texture[NumTextures]); //Temp Gen Function



// Temp Texture Properties

glBindTexture(GL_TEXTURE_2D, Texture[NumTextures]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.imgsizex, tex.imgsizey, 0, GL_RGB, GL_UNSIGNED_BYTE, &imgdata);
NumTextures++; //Add One More Texture To The List (Mostly For Compiler Function)
//---------------------------\\


return TRUE;
}


I have gone from a red colored thing that looks sorta like my bitmap to a pure red screen. If I keep going at this rate my computer will explode before I fix this.
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Galileo430
Galileo430
Still No Good, I think I am going to rip out my Texture code and recode it. Maybe I have a small error no one sees.
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Poontardis
Poontardis
Coding the bitmap loading yourself is a good exercise worth doing, but in the interests of your sanity (if you still can't get it working ):

PaulyG has code for loading targa images in and binding them to textures on his OpenGL webpage

Edited by - poontardis on October 27, 2000 5:07:18 AM
Galileo430
Galileo430
Fixed it..

Had to do with glColor3f.

For some reason it''s was clashing with the texture.
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Ampere
Ampere
That''ll happen if you use glColor3f(numGreaterThanZero, 0.0f, 0.0f) and GL_MODULATE for your TexEnv.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.