???, glTexSubImage2D not work?
Hi,
I do not succeed to make to work glTexSubImage2D function, when run my app I see only a white surface...
My attempt is to create a fast 2d render surface (like DirectDraw or faster).
This is the code (It is Pascal,sorry):
procedure glInit();
begin
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 1, 1, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// glRasterPos2i(0, 480);
// glPixelZoom(1.0, -1.0);
UDIB := TDIBUltra.CreateFromFile('bg.bmp');
Ppixelmap := UDIB.Adr_Image; //this is a pointer to a DIB 565 16-bit image
end;
procedure glDraw();
begin
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexSubImage2D( GL_TEXTURE_2D,0,0,0, 640, 480,
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, Ppixelmap);
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex3i(0, 0, 0);
glTexCoord2i(640, 0); glVertex3i(640, 0, 0);
glTexCoord2i(640, 480); glVertex3i(640, 480, 0);
glTexCoord2i(0, 480); glVertex3i(0, 480, 0);
glEnd();
end;
procedure glResizeWnd(Width, Height : Integer);
begin
if (Height = 0) then // prevent divide by zero exception
Height := 1;
glViewport(0, 0, Width, Height); // Set the viewport for the OpenGL window
glMatrixMode(GL_PROJECTION); // Change Matrix Mode to Projection
glLoadIdentity(); // Reset View
glOrtho(0, 1, 1, 0, 0, 1);
glMatrixMode(GL_MODELVIEW); // Return to the modelview matrix
glLoadIdentity(); // Reset View
end;
Sorry for my BAD English!
Thanks thousands
Where, and how, do you create the texture object? glTexSubImage is used to update an existing texture, and can not be used to create one.
ehmmm... you have right! :)
sorry I'm a newbie with OpenGL :)
I have update my glInit() procedure and now work fine!
Code:
procedure glInit();
begin
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 1, 1, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glGenTextures(1, @texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 512, 0, GL_RGB,
GL_UNSIGNED_SHORT_5_6_5, nil );
UDIB := TDIBUltra.CreateFromFile('bg.bmp');
Ppixelmap := UDIB.Adr_Image; //this is a pointer to a DIB 565 16-bit image
end;
Thx a lot!!!!
sorry I'm a newbie with OpenGL :)
I have update my glInit() procedure and now work fine!
Code:
procedure glInit();
begin
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 1, 1, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glGenTextures(1, @texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 512, 0, GL_RGB,
GL_UNSIGNED_SHORT_5_6_5, nil );
UDIB := TDIBUltra.CreateFromFile('bg.bmp');
Ppixelmap := UDIB.Adr_Image; //this is a pointer to a DIB 565 16-bit image
end;
Thx a lot!!!!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement