• Advertisement
Sign in to follow this  

Black rectangle in rendering texture

This topic is 974 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I create textures (for example, I just fill the texture color), and render their. But, for some reason, to the upper edge added black rectangle.

Screenshot:

8hAIh.jpg
    

var
Textures: array of GLuint;

procedure LoadTexture(const TextureID: Byte; var Texture: GLuint);
var
//
w, h: Cardinal;
//
Data: PByteArray;
begin
//
if TextureID = 0 then
//
  begin
//
w:=512; h:=512;
  end
                 else
//
  begin
//
w:=128; h:=64;
  end;

//
GetMem(Data, w * h * 3);

//
if TextureID = 0 then
//
FillChar(Data^, w * h * 3, 204)
                 else
//
FillChar(Data^, w * h * 3, 102);

//
glBindTexture(GL_TEXTURE_2D, Texture);

//
glTexParameteri(GL_TEXTURE_2D,
//
GL_TEXTURE_MAG_FILTER, GL_NEAREST);

//
glTexParameteri(GL_TEXTURE_2D,
//
GL_TEXTURE_MIN_FILTER, GL_LINEAR);

//
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,
//
w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, Data);

//
FreeMem(Data, w * h * 3);
//
Data:=nil;
end;

procedure glInit;
begin
//
glEnable(GL_TEXTURE_2D);

//
SetLength(Textures, 2);
//
glGenTextures(1, @Textures[0]);
//
LoadTexture(0, Textures[0]);
//
glGenTextures(1, @Textures[1]);
//
LoadTexture(1, Textures[1]);

//
glClearColor(1, 1, 1, 0);
//
glShadeModel(GL_SMOOTH);
//
glClearDepth(1);
//
glDisable(GL_DEPTH_TEST);
//
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

//
glViewport(0, 0, 800, 600);
//
glMatrixMode(GL_PROJECTION);
//
glLoadIdentity;
//
glOrtho(0, 800, 600, 0, 0, 1);
//
glMatrixMode(GL_MODELVIEW);
//
glLoadIdentity;
end;

procedure glDraw;
begin
//
glClearColor(1, 1, 1, 0);
//
glClear(GL_COLOR_BUFFER_BIT or
  GL_DEPTH_BUFFER_BIT);

//
glBindTexture(GL_TEXTURE_2D, Textures[0]);
//
glBegin(GL_QUADS);
//
glTexCoord2f(0, 0);
//
glVertex2f(0,   0);
//
glTexCoord2f(1, 0);
//
glVertex2f(512, 0);
//
glTexCoord2f(1, 1);
//
glVertex2f(512, 512);
//
glTexCoord2f(0, 1);
//
glVertex2f(0,   512);
//
glEnd;

//
glBindTexture(GL_TEXTURE_2D, Textures[1]);
//
glBegin(GL_QUADS);
//
glTexCoord2f(0, 0);
//
glVertex2f(128,   64);
//
glTexCoord2f(1, 0);
//
glVertex2f(256, 64);
//
glTexCoord2f(1, 1);
//
glVertex2f(256, 128);
//
glTexCoord2f(0, 1);
//
glVertex2f(128, 128);
//
glEnd;
end;

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement