racumin
11-02-2009, 10:11 PM
Hi, is the call to multiple glBegin() and glEnd() the most efficient way to display a grid based graphics?
For example, I have this code:
for (int i = 0; i < MAP_HEIGHT; i++) {
for (int j = 0; j < MAP_WIDTH; j++) {
//determine what kind of object is in this position
//ex. if (node.object == grass) glBindTexture(GL_TEXTURE_2D, grass);
glBegin(GL_QUADS);
glTexCoord2d(0, 1);
glVertex2d(j * (window.GetWidth() / MAP_WIDTH), (i + 1) * (window.GetHeight() / MAP_HEIGHT));
glTexCoord2d(1, 1);
glVertex2d((j + 1) * (window.GetWidth() / MAP_WIDTH), (i + 1) * (window.GetHeight() / MAP_HEIGHT));
glTexCoord2d(1, 0);
glVertex2d((j + 1) * (window.GetWidth() / MAP_WIDTH), i * (window.GetHeight() / MAP_HEIGHT));
glTexCoord2d(0, 0);
glVertex2d(j * (window.GetWidth() / MAP_WIDTH), i * (window.GetHeight() / MAP_HEIGHT));
glEnd();
}
}
Or are there any other optimal solutions for this?
For example, I have this code:
for (int i = 0; i < MAP_HEIGHT; i++) {
for (int j = 0; j < MAP_WIDTH; j++) {
//determine what kind of object is in this position
//ex. if (node.object == grass) glBindTexture(GL_TEXTURE_2D, grass);
glBegin(GL_QUADS);
glTexCoord2d(0, 1);
glVertex2d(j * (window.GetWidth() / MAP_WIDTH), (i + 1) * (window.GetHeight() / MAP_HEIGHT));
glTexCoord2d(1, 1);
glVertex2d((j + 1) * (window.GetWidth() / MAP_WIDTH), (i + 1) * (window.GetHeight() / MAP_HEIGHT));
glTexCoord2d(1, 0);
glVertex2d((j + 1) * (window.GetWidth() / MAP_WIDTH), i * (window.GetHeight() / MAP_HEIGHT));
glTexCoord2d(0, 0);
glVertex2d(j * (window.GetWidth() / MAP_WIDTH), i * (window.GetHeight() / MAP_HEIGHT));
glEnd();
}
}
Or are there any other optimal solutions for this?