Advertisement

[DESIGN] Best Method to show a *chessboard* grid?

Started by February 01, 2001 11:14 PM
7 comments, last by Pure Krome 24 years ago
Hi all. I''m trying to impliment something like a chess board. I''ve got two display lists, that are 3D boxes, one white, one black. I was doing a simple 2D loop, incrementing the position with each iteration before *calling* the display list. It works. But i''m getting 2 or 3 fps =( Is there a better way to do this? Also, as far as i know, i think the only *efficient coding* is this..

  glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
  glShadeModel(GL_SMOOTH);
  glClearDepth(1.0f);                                   // Depth Buffer Setup
  glEnable(GL_DEPTH_TEST);                              // Enables Depth Testing
  glDepthFunc(GL_LEQUAL);                               // The Type Of Depth Testing To Do
  //glFrontFace(GL_CW);
  glEnable(GL_CULL_FACE);                               // Enable Back Face Culling;
 
Any suggestions please? -thank you- -PK-
-PK-
You just want a checker board pattern? If so, make a texture of a checkerboard, then map it to a quad. Simple & fast.

There are many other ways to do what you want.

Advertisement
um. i actually can't do it that way. (use a texture)

My game is not really a chess board - i used that as an example. Looks like it's a bad example.

the *board* is actually a grid. Each *sqaure* is .. lets say .. each square could be a random colour.

** SO it's like a massive chessboard, with each square being a random colour **

that is why i'm making cubes.

-PK-

Edited by - Pure Krome on February 2, 2001 1:07:09 AM
-PK-
Well, you can still use textures. Anyway, do you really need a cube? (6 sides) or do you just need 1 face?
You could just go into a loop, and create 1 face (using whatever color),next face, change color...and so on. So you end up with say 64x64 grid of say 8x8 squares. In this case, you would end up with 64*8*2 polys though. That is for 1 face each. Mult another 6 for cubes, so you end up with 6000+ polys...

So what was the question--I mean you ask is this an efficent way, but you don''t show the code, you show the init phase...


Ok. I''ve included some (very poor) code to explain what i''m doing.

In my int main(void) function....
  ...glutDisplayFunc(RenderScene);glutIdleFunc(RenderScene);...  


now this is my *edited* version of RenderScene function
  void RenderScene(void){  int x, y = 1;  // UPDATE POSITION FIRST BEFORE WE SHOW ANYTHING.  // Are we already moving or turning??  if (camera.IsMoving() == true) {    glLoadIdentity();    camera.UpdateMoving();    camera.LookAt();  }  else     camera.Update();      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   // Clear Screen And Depth Buffer// Draw ground	glColor3f(0.9f, 0.9f, 0.9f);	glBegin(GL_QUADS);		glVertex3f(-100.0f, 0.0f, -100.0f);		glVertex3f(-100.0f, 0.0f,  100.0f);		glVertex3f( 100.0f, 0.0f,  100.0f);		glVertex3f( 100.0f, 0.0f, -100.0f);	glEnd();  // Loop through each Row in the Map  for (y=0; y < World.YAxisLength(); y++)  {    for (x=0; x < World.XAxisLength() / 60; x++)    {      glPushMatrix();      glTranslatef(1.0f * x, 1.0f, 1.0f * y );      // Colour the BOX (not the top surface)      glColor3fv(colour_purple);      glCallList(terrainBox);      // Check to see what the terrain is, so we can define the colour      switch (World.TerrainTile(x, y)) {        case ''~'' : glColor3fv(colour_blue); break;        case ''G'' : glColor3fv(colour_green); break;        case ''F'' : glColor3fv(colour_dark_green); break;        default: glColor3fv(colour_red); break;      }      // Colour the top quad      glCallList(terrainSurface);      glPopMatrix();    }  }  frame++;	time=glutGet(GLUT_ELAPSED_TIME);	if (time - timebase > 1000) {		sprintf(s,"FPS:%4.2f",frame*1000.0/(time-timebase));		timebase = time;				frame = 0;	}	glColor3f(0.0f,1.0f,1.0f);  openGLScene.SetOrthographicProjection();  glPushMatrix(); 	glLoadIdentity(); 	renderBitmapString(30,35,(void *)font,s); 	renderBitmapString(30,55,(void *)font,"Esc - Quit"); 	glPopMatrix(); 	openGLScene.ResetPerspectiveProjection();	glutSwapBuffers();}  



I''m trying to show a map, which is an ascii file.

Later on, i wish to change the sqaure face tiles into something different, like triangles to represent hills or mountains, etc.

I''m using an ascii map, becuase the game is TEXT BASED (A MUD, using telnet client, etc...), and certain parts of the map are shown during the game.


Please help folks.



-PK-
-PK-
A/ r u drawing stuff that doesnt appear on the screen?
B/ calling display list for very simple objects eg a quad will slow the program down.
C/ this could be slow "renderBitmapString"


http://members.xoom.com/myBollux
Advertisement
>>A/ r u drawing stuff that doesnt appear on the screen?

yes i am. Most of the sides of the boxes are touching each other, which means they are hidden. This is a massive waste,of course. I do not know how to *hide those*.

B/ calling display list for very simple objects eg a quad will slow the program down.

hmm .. ok ....

C/ this could be slow "renderBitmapString"

hmm .. ok ..


I think my biggest problem is how do i hide all the sides of the squares that are *hidden*.

Do i need to place my grid of sqaures into some TREE structure, which knows how to hide any *hidden* faces?




-PK-
-PK-
zedzeek??
elixer??

Anyone out there that can help me ? =`(


-PK-
-PK-
For each tileboxthing in your loop check if there is a tile to the left, if there is not, draw the left side, repeat for right side and all other sides.

This topic is closed to new replies.

Advertisement