Skip to main content
GameDev.net gamedev.net
🔒 Locked

2d tiles

Started by cb007sax Aug 12, 2002 at 7:28 PM 0 replies 600+ views
Original Post
cb007sax
cb007sax
Here is my drawing function for a 2d tile map int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing { POINT p; GetCursorPos(&p); dxInput.UpdateDevices(); if (KeyDown(dxInput.keystate, DIK_UP)) upTranslate -= 30.0f; if (KeyDown(dxInput.keystate, DIK_DOWN)) upTranslate += 30.0f; if (KeyDown(dxInput.keystate, DIK_LEFT)) rightTranslate -= 30.0f; if (KeyDown(dxInput.keystate, DIK_RIGHT)) rightTranslate += 30.0f; if (p.x <= 10) rightTranslate -= 5.0f; if (p.y <= 10) upTranslate -= 5.0f; if (p.x >= 789) rightTranslate += 5.0f; if (p.y >= 589) upTranslate += 5.0f; int row=0, col=0, rrow=0, ccol=0; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glBindTexture(GL_TEXTURE_2D, texture[1]); glLoadIdentity(); for(row = 0; row<9;row++) for(col = 0; col<13;col++) { rrow = (row << 7)-rightTranslate; ccol = (col << 6)-upTranslate; glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(1.0f, 1.0f); glVertex3f(float(rrow), float(ccol), 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(float(rrow + (64)), float(ccol - ( 32 )), 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(float(rrow + (64)), float(ccol + ( 32 )), 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(float(rrow + 128), float(ccol), 0.0f); glEnd(); } for(row = 0; row<9; row++) for(col = 0; col<13;col++) { rrow = (row << 7)-64-rightTranslate; ccol = (col << 6)+32-upTranslate; glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(1.0f, 1.0f); glVertex3f(float(rrow), float(ccol), 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(float(rrow + (64)), float(ccol - ( 32 )), 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(float(rrow + (64)), float(ccol + ( 32 )), 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(float(rrow + 128), float(ccol), 0.0f); glEnd(); } return TRUE; // Everything Went OK } It''s for a 1024x768 resoultion. On some of my friends computers it''s not smooth at all, is there a way to make thsi faster. Is there some sort of method i''m missing? Any help would be appreciated.
zedzeek
zedzeek
MOST IMPORTANT first find out the bottleneck on their computer

one thing youre doing is calling a tri strip for every quad, u want to minimize glBegin(..) .. glEnd() calls

using

glBegin(GL_QUADS);
for(row = 0; row<9; row++)
for(col = 0; col<13;col++)
{
rrow = (row << 7)-64-rightTranslate;
ccol = (col << 6)+32-upTranslate;
glTexCoord2f(1.0f, 1.0f); glVertex3f(float(rrow), float(ccol), 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(float(rrow + (64)), float(ccol - ( 32 )), 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(float(rrow + (64)), float(ccol + ( 32 )), 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(float(rrow + 128), float(ccol), 0.0f);
}
glEnd();

will prolly be quicker (then again it wont be if u make the window say 320x240 big + the fps increases dramatically then u are fillrate bound)



http://uk.geocities.com/sloppyturds/gotterdammerung.html

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.