Hi,
I am trying to make a basic tile scrolling program but am having problems implementing the culling of tiles which are not draw on the screen.
At the moment i have smooth movement to the right, but it seems to be jerky going to the left. Also i lose my very first and very last tile because i have overlapped the tiles to draw some offscreen. IE if 12 tiles fit across the screen i have 14 drawn for my scrolling.
I am unsure off where to go from here. If anyone can suggest methods or something i could do different to cull my tiles that are offscreen i would greatly appreciate it!
here is my rendering and keyboard routine...
float xaxis = -7.75f;
const float xaxisperm = -7.75f;
int mapxsize=0;
int mapysize=0;
int texture_offset_x = 1;
int texture_offset_y = mapysize;
// no more than 1.0f xaxis deviation either way....
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(xaxis, -5.0, -13); // Move Left 1.5 Units And Into The Screen 6.0
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// grid.....
glEnable(GL_TEXTURE_2D);
for (GLfloat j=0;j<14;j++)
{
for (GLfloat k=13;k>0;k--)
{
glBindTexture(GL_TEXTURE_2D, texture[(mapdata[j+texture_offset_x][k+texture_offset_y])].texID);
glBegin(GL_QUADS);
// glColor3f(0.0f,1.0f,0.0f);
glTexCoord2d(0.0,1.0); glVertex3f(j-0.5f, k+0.5f, 0.0f);
glTexCoord2d(1.0,1.0); glVertex3f(j+0.5f, k+0.5f, 0.0f);
glTexCoord2d(1.0,0.0); glVertex3f(j+0.5f, k-0.5f, 0.0f);
glTexCoord2d(0.0,0.0); glVertex3f(j-0.5f, k-0.5f, 0.0f);
glEnd();
}
}
// right bar
glLoadIdentity(); // reset matrix
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glTranslatef(4.55f,5.5f,-12.5f);
glDisable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,-11.0f,0.0f);
glVertex3f(3.0f,-11.0f,0.0f);
glVertex3f(3.0f,0.0f,0.0f);
glColor3f(1.0f,1.0f,1.0f);
glEnd();
glEnable(GL_TEXTURE_2D);
return true; // Everything Went OK
}
int CheckKeyboardInput()
{
if (keys[VK_ESCAPE]) // Was ESC Pressed?
{
done=TRUE; // ESC Signalled A Quit
}
if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow("Opengl Tile Engine v1.2",SCREENWIDTH,SCREENHEIGHT,BITSPERPIXEL,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
if (keys[VK_LEFT])
{
if (texture_offset_x > 0)
{
xaxis += 0.1f;
if (xaxis > -6.75f) // check to see if we have moved more than 1 square left
{
texture_offset_x -=1; // if so move the texture coords left
xaxis = -7.75f; // and reset the xaxis to normal
if (texture_offset_x < 0)
texture_offset_x = 0;
}
}
}
if (keys[VK_RIGHT])
{
if (texture_offset_x < mapxsize-14)
{
xaxis -= 0.1f;
if (xaxis < -8.75) // same has left but for the right movement.....
{
texture_offset_x +=1;// as above
xaxis = -7.75; // as above
if (texture_offset_x> mapxsize-14)
texture_offset_x -=1;
}
}
}
return true;
}
mapdata is a vector of my map and mapxsize is determined when i load my map in.
Werdy666

My Homepage : http://werdy666.20megsfree.com/
[edited by - werdy666 on September 29, 2002 10:51:35 AM]