Brainer
20-11-2010, 12:42 PM
Hello. :)
For my little project, I decided to move back to OpenGL 2.0. The project's a very simple 2D game I'm going to work on with my classmates.
I've got a question regarding rendering backgrounds. I have a 128x128 texture which I want to use as a background. Here's how I do it:
procedure TMainForm.RenderBackground;
var
Test: TTexture;
I, J, CellsX, CellsY: Integer;
Viewport: array[0..3] of GLint;
begin
Test := TextureLibrary[0];
I := 0;
J := 0;
Test.Bind();
glPushMatrix();
glGetIntegerv(GL_VIEWPORT, @Viewport[0]);
CellsX := (Viewport[2] div Test.TextureWidth) + 1;
CellsY := (Viewport[3] div Test.TextureHeight) + 1;
while (True) do
begin
glLoadIdentity();
glTranslatef(I * Test.TextureWidth, J * Test.TextureHeight, 0.0);
glBegin(GL_QUADS);
glTexCoord2i(0, Test.TextureHeight);
glVertex2i(0, 0);
glTexCoord2i(Test.TextureWidth, Test.TextureHeight);
glVertex2i(Test.TextureWidth, 0);
glTexCoord2i(Test.TextureWidth, 0);
glVertex2i(Test.TextureWidth, Test.TextureHeight);
glTexCoord2i(0, 0);
glVertex2i(0, Test.TextureHeight);
glEnd();
if (I < CellsX) then
Inc(I)
else
begin
I := 0;
Inc(J);
end;
if (J >= CellsY) then
break;
end;
glPopMatrix();
Test.UnBind();
end;
I feel it's not the best way to do the background, so if you could possibly suggest me a better way of doing it, I'd really appreciate it. Note that in the example I use GL_TEXTURE_RECTANGLE_EXT.
For my little project, I decided to move back to OpenGL 2.0. The project's a very simple 2D game I'm going to work on with my classmates.
I've got a question regarding rendering backgrounds. I have a 128x128 texture which I want to use as a background. Here's how I do it:
procedure TMainForm.RenderBackground;
var
Test: TTexture;
I, J, CellsX, CellsY: Integer;
Viewport: array[0..3] of GLint;
begin
Test := TextureLibrary[0];
I := 0;
J := 0;
Test.Bind();
glPushMatrix();
glGetIntegerv(GL_VIEWPORT, @Viewport[0]);
CellsX := (Viewport[2] div Test.TextureWidth) + 1;
CellsY := (Viewport[3] div Test.TextureHeight) + 1;
while (True) do
begin
glLoadIdentity();
glTranslatef(I * Test.TextureWidth, J * Test.TextureHeight, 0.0);
glBegin(GL_QUADS);
glTexCoord2i(0, Test.TextureHeight);
glVertex2i(0, 0);
glTexCoord2i(Test.TextureWidth, Test.TextureHeight);
glVertex2i(Test.TextureWidth, 0);
glTexCoord2i(Test.TextureWidth, 0);
glVertex2i(Test.TextureWidth, Test.TextureHeight);
glTexCoord2i(0, 0);
glVertex2i(0, Test.TextureHeight);
glEnd();
if (I < CellsX) then
Inc(I)
else
begin
I := 0;
Inc(J);
end;
if (J >= CellsY) then
break;
end;
glPopMatrix();
Test.UnBind();
end;
I feel it's not the best way to do the background, so if you could possibly suggest me a better way of doing it, I'd really appreciate it. Note that in the example I use GL_TEXTURE_RECTANGLE_EXT.