Skip to main content
gamedev.net
🔒 Locked

Texture problem

Started by 255 Oct 3, 2002 at 2:26 PM 1 replies 400+ views
Original Post
255
255
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?
iNsAn1tY
iNsAn1tY
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]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
255
255
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

Topic Locked

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

Sign in to reply to this topic.