Archived

This topic is now archived and is closed to further replies.

255

Texture problem

Recommended Posts

255    368
I''m having trouble with texturing, when I load and render a texture it only shows the color of the polygon. The loading code (I''m using delphi, could that be a problem?): glGenTextures(1, @TexName); glBindTexture(GL_TEXTURE_2D, TexName); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, Width, //128 Height, //128 0, GL_RGBA, GL_UNSIGNED_INT, Data ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); Where Data is a dynamic array of type: TTexRGBA = packed record R, G, B, A: GLuint; end; For testing I tried to load the texture with glGetTexImage just after loading it. The result is an array of 0s although the data passed to glTexImage2D was ok. glGetError returns 0 and texturing is enabled via glEnable(GL_TEXTURE_2D). What am I doing wrong?

Share this post


Link to post
Share on other sites
iNsAn1tY    476
No, that code won't work (I think, I have little experience with Pascal/Delphi). You're defining this:


  
TTexRGBA = packed record
R, G, B, A: GLuint;
end;


What you have to do is create a dynamic array, like this (this is VB notation, first thing that came to hand):


  
// Create one dynamic array here...

Dim BitmapBits() As GLubyte

// Figure out the size of the image in

// bytes here (this works for me)...

BitmapBitsize = ((BitmapHeight * BitmapWidth) * (BitmapBitCount / 8)) - 1

// ...and then here, make the dynamic

// array the size you need it...

Redim BitmapBits(BitmapSize)

//Read in your texture here...



Basically, you have to have one dynamic array of GLubytes, into which you read your texture. Then, you send that array to glTexImage2D, along with GL_RGBA and GL_UNSIGNED_BYTE, and OpenGL will linearly run through every array element and extract the data...


Movie Quote of the Week:

"You've been eating retard sandwiches again."
- Birdman, Beautiful Girls.
Try http://uk.geocities.com/mentalmantle. Seriously. It's brilliant.
And I just completely redesigned it so it looks even better.
DarkVertex Beta 0.8 available soon!


[edited by - iNsAn1tY on October 3, 2002 3:43:37 PM]

Share this post


Link to post
Share on other sites
255    368
Thanks! I got mixed up with int and byte. The colors were from the range 0-255 so it was obvious that i couldn''t see anything. :D

Share this post


Link to post
Share on other sites