PDA

View Full Version : OpenGL Texture problem...



M109uk
24-03-2007, 10:37 PM
Hi all,

Im having a very annoying problem, i have an opengl engine with a texture list class. When i add a texture, all seems to go through ok, and no problems with creating the texture.

How ever no matter what i do the texture will not bind, all i get is a blank image, i copy the pixels to an sdl surface and save it and the texture is there.

Below i have included the code i am using:

Creating the texture:

function TXTexture.GLCreate(const Index: Cardinal): Boolean;
var
Target: TXTarget;
W,H: Integer;
begin
glGenTextures(1, @Frames[Index].Index);
Log.Debug('Generating OpenGL texture '''+MClassname+''' ['+InttoStr(ID)+'/'+InttoStr(Frames[Index].Index)+']', 'XTexture');

H := Propertise.GetInt('height', 0);
W := Propertise.GetInt('width', 0);

Target := TXTarget(Propertise.GetInt('target', 1));
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Frames[Index].Index);

// gluBuild2DMipmaps(XTarget(Target), 3, W, H, GL_BGR, GL_UNSIGNED_BYTE, Frames[Index].Pixels);
// gluBuild2DMipmaps(XTarget(Target), GL_BGRA, W, H, GL_BGRA, GL_UNSIGNED_BYTE, Frames[Index].Pixels);
glTexImage2D(GL_TEXTURE_2D, 0, 3, W, H, 0, GL_BGR, GL_UNSIGNED_BYTE, Frames[Index].Pixels);

If (Target = xt1D) Or (Target = xt2D) Or (Target = xt3D) Then
Begin
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// glTexParameteri(XTarget(Target), GL_TEXTURE_MAG_FILTER, XMagFilter(TXMagFilter(Propertise.GetInt('filter.m ag', 0))));
// glTexParameteri(XTarget(Target), GL_TEXTURE_MIN_FILTER, XMinFilter(TXMinFilter(Propertise.GetInt('filter.m in', 1))));
End Else
Begin
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, XMagFilter(TXMagFilter(Propertise.GetInt('filter.m ag', 0))));
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, XMinFilter(TXMinFilter(Propertise.GetInt('filter.m in', 0))));
End;

Result := (Frames[Index].Index > 0);
end;


I have changed the code a little to see if i can figure out the problem.

Bind:

Target := TXTarget(Propertise.GetInt('target', 1));
glEnable(XTarget(Target));
glBindTexture(XTarget(Target), Frames[0].Index);
// glBindTexture(XTarget(Target), Frames[Frame].Index);


I have been trying to figure this out for the last 2 days but have not got anywhere.

Many thanks
Nic

JernejL
25-03-2007, 10:39 AM
change:


glTexImage2D(GL_TEXTURE_2D, 0, 3, W, H, 0, GL_BGR, GL_UNSIGNED_BYTE, Frames[Index].Pixels);

to


glTexImage2D(GL_TEXTURE_2D, 0, 3, W, H, 0, GL_BGR, GL_UNSIGNED_BYTE, @Frames[Index].Pixels);

if pixels is array, use:


glTexImage2D(GL_TEXTURE_2D, 0, 3, W, H, 0, GL_BGR, GL_UNSIGNED_BYTE, @Frames[Index].Pixels[0]);

but if it is bind problem, then debug your app with gldebugger.

M109uk
25-03-2007, 10:58 AM
The pixels are already stored as a pointer, (PByteArray), i have tried both your suggestions and nothing seems to change.

I am using SDL to load the image, and then im copying the pixel data from the sdl surface to my own pixel pointer, i have tried using both my pixel data and the sdl surface pixel data in the glTexImage2D but with no effect.

I will try glDebugger, can you tell me where to get it from?

Thanks

Edit:

I have downloaded gDEBugger from gremedy, and have debugged my program & engine, it seemed the textures are created without a problem (the only problem being they are upside down), so now im even more lost, i can not see where it can be going wrong anywhere :s

M109uk
25-03-2007, 12:27 PM
ahh finally figured it out,

i made a really dumb/stupid mistake..

It ended up because i was setting the resolution to fit a window, and i was still using some test code that i forgot about, so i replaced it with SDL_SetVideoMode and now all works create :)

Thanks again