3 Replies - 915 Views - Last Post: 12 February 2013 - 09:38 AM Rate Topic: -----

#1 Jaey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-February 13

opengl chessboard

Posted 11 February 2013 - 05:53 PM

Hi all,

I'm trying to create 5x5 chessboard in OpenGL. I am looking to create the first 25-cells board before doing the 5x5x5 version.

The code below keeps giving me an error saying the drawBlackCell cannot take 3 arguments. Can anybody help with this pls or show me what I am doing wrong?

Here is the code i seem to have a problem with:
#include<windows.h>
#include <glut.h>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
float _angle = 0;
double i;
int k;
bool white_or_black;

GLuint _displayListId_blackArea; //The OpenGL id of the display list
GLuint _displayListId_whiteArea; //The OpenGL id of the display list
 
void handleKeypress(unsigned char key,int x,int y)
{
switch(key)
{
case 27:
exit(0);
}
}
 
void handleResize(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,(double)w/(double)h,1.0,200);
gluLookAt(0.0f,5.5f, 15.0f,
0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f);
}
 
void draw_BlackArea()
{
// glPushMatrix();
//glTranslatef(1.5f,0.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(0.05f,0.05f,0.05f);
glTranslatef(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.50f,0.0f,0.0f);
glVertex3f(1.5f,0.3f,0.0f);
glVertex3f(0.0f,0.3f,0.0f);
glEnd();
 
 
glBegin(GL_QUADS);
glColor3f(0.05f,0.05f,0.05f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,-1.5f);
glVertex3f(0.0f,0.3f,-1.5f);
glVertex3f(0.0f,0.3f,0.0f);
glEnd();
 
 
glBegin(GL_QUADS);
glColor3f(0.05f,0.05f,0.05f);
glVertex3f(1.5f,0.0f,0.0f);
glVertex3f(1.5f,0.0f,-1.5f);
glVertex3f(1.5f,0.3f,-1.5f);
glVertex3f(1.5f,0.3f,0.0f);
glEnd();
 
glBegin(GL_QUADS);
glColor3f(0.05f,0.05f,0.05f);
glVertex3f(0.0f,0.0f,-1.5f);
glVertex3f(1.50f,0.0f,-1.5f);
glVertex3f(1.5f,0.3f,-1.5f);
glVertex3f(0.0f,0.3f,-1.5f);
glEnd();
 
 
glBegin(GL_QUADS);
glColor3f(0.05f,0.05f,0.05f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.50f,0.0f,0.0f);
glVertex3f(1.5f,0.0f,-1.5f);
glVertex3f(0.0f,0.0f,-1.5f);
glEnd();
 
 
glBegin(GL_QUADS);
glColor3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.3f,0.0f);
glVertex3f(1.50f,0.3f,0.0f);
glVertex3f(1.5f,0.3f,-1.5f);
glVertex3f(0.0f,0.3f,-1.5f);
glEnd();
//    glPopMatrix();
 
}
void draw_whiteArea()
{
// glPushMatrix();
glBegin(GL_QUADS);
glColor3f(0.05f,0.05f,0.05f);
glTranslatef(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.50f,0.0f,0.0f);
glVertex3f(1.5f,0.3f,0.0f);
glVertex3f(0.0f,0.3f,0.0f);
glEnd();
 
 
glBegin(GL_QUADS);
glColor3f(0.05f,0.05f,0.05f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,-1.5f);
glVertex3f(0.0f,0.3f,-1.5f);
glVertex3f(0.0f,0.3f,0.0f);
glEnd();
 
 
glBegin(GL_QUADS);
glColor3f(0.05f,0.05f,0.05f);
glVertex3f(1.5f,0.0f,0.0f);
glVertex3f(1.5f,0.0f,-1.5f);
glVertex3f(1.5f,0.3f,-1.5f);
glVertex3f(1.5f,0.3f,0.0f);
glEnd();
 
glBegin(GL_QUADS);
glColor3f(0.05f,0.05f,0.05f);
glVertex3f(0.0f,0.0f,-1.5f);
glVertex3f(1.50f,0.0f,-1.5f);
glVertex3f(1.5f,0.3f,-1.5f);
glVertex3f(0.0f,0.3f,-1.5f);
glEnd();
 
 
glBegin(GL_QUADS);
glColor3f(0.05f,0.05f,0.05f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.50f,0.0f,0.0f);
glVertex3f(1.5f,0.0f,-1.5f);
glVertex3f(0.0f,0.0f,-1.5f);
glEnd();
 
 
glBegin(GL_QUADS);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(0.0f,0.3f,0.0f);
glVertex3f(1.50f,0.3f,0.0f);
glVertex3f(1.5f,0.3f,-1.5f);
glVertex3f(0.0f,0.3f,-1.5f);
glEnd();
// glPopMatrix();
 
}
 
void initRendering()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glClearColor(0.0f,0.0f,0.2f,1.0f);
//Set up a display list for drawing a cube
_displayListId_blackArea = glGenLists(1); //Make room for the display list
glNewList(_displayListId_blackArea, GL_COMPILE); //Begin the display list
draw_BlackArea(); //Add commands for drawing a black area to the display list
glEndList(); //End the display list
 
//Set up a display list for drawing a cube
_displayListId_whiteArea = glGenLists(2); //Make room for the display list
glNewList(_displayListId_whiteArea, GL_COMPILE); //Begin the display list
draw_whiteArea(); //Add commands for drawing a black to the display list
glEndList(); //End the display list
}


void drawScene()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-2.5*1.5, 0.0, 2.5*1.5);

const unsigned BOARD_SIZE = 5;

for(unsigned i = 0; i < BOARD_SIZE; ++i){
 for(unsigned j = 0; j < BOARD_SIZE; ++j){
    drawBoardCell(i,j, (i*BOARD_SIZE + j) % 2 == 0);
  }
}

}
void drawBoardCell(const int row, const int col, const bool isBlack){
  glPushMatrix();
  glTranslatef(col+1.5,0.0,row);
  const int callId = isBlack ? _displayListId_blackArea : _displayListId_whiteArea;
  glCallList(callId);
  glPopMatrix();

}

int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(400,400);
 
glutCreateWindow("chessboard");
initRendering();
glutFullScreen();
 
glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
 
glutMainLoop();
 
return 0;
 
}

This post has been edited by modi123_1: 11 February 2013 - 11:07 PM
Reason for edit:: please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: opengl chessboard

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: opengl chessboard

Posted 11 February 2013 - 08:19 PM

Where is drawBlackCell() defined?
Was This Post Helpful? 0
  • +
  • -

#3 Jaey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-February 13

Re: opengl chessboard

Posted 12 February 2013 - 02:10 AM

View PostButchDean, on 11 February 2013 - 08:19 PM, said:

Where is drawBlackCell() defined?

Thanks for your reply. Everytime i define it, it gives me an additional error.
I initially defined it as
const int drawBlackCell(*drawBlackCell)();



is that right pls?
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: opengl chessboard

Posted 12 February 2013 - 09:38 AM

No, that isn't C++.

int drawBlackCell();



Maybe? It depends on how your code is written.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1