openGPMP
Open Source Mathematics Package
Public Member Functions | Private Attributes | List of all members
Checkerboard Class Reference

Public Member Functions

 Checkerboard (int width, int depth)
 
double centerx ()
 
double centerz ()
 
void create ()
 
void draw ()
 

Private Attributes

int displayListId
 
int width
 
int depth
 

Detailed Description

Definition at line 104 of file openGL_bounce.c.

Constructor & Destructor Documentation

◆ Checkerboard()

Checkerboard::Checkerboard ( int  width,
int  depth 
)
inline

Definition at line 110 of file openGL_bounce.c.

110  : width(width), depth(depth) {
111  }

Member Function Documentation

◆ centerx()

double Checkerboard::centerx ( )
inline

Definition at line 113 of file openGL_bounce.c.

113  {
114  return width / 2;
115  }

References width.

Referenced by display().

◆ centerz()

double Checkerboard::centerz ( )
inline

Definition at line 116 of file openGL_bounce.c.

116  {
117  return depth / 2;
118  }

References depth.

Referenced by display().

◆ create()

void Checkerboard::create ( )
inline

Definition at line 120 of file openGL_bounce.c.

120  {
121  displayListId = glGenLists(1);
122  glNewList(displayListId, GL_COMPILE);
123  GLfloat lightPosition[] = {4, 3, 7, 1};
124  glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
125  glBegin(GL_QUADS);
126  glNormal3d(0, 1, 0);
127 
128  for (int x = 0; x < width - 1; x++) {
129  for (int z = 0; z < depth - 1; z++) {
130  glMaterialfv(GL_FRONT,
131  GL_AMBIENT_AND_DIFFUSE,
132  (x + z) % 2 == 0 ? RED : WHITE);
133 
134  glVertex3d(x, 0, z);
135  glVertex3d(x + 1, 0, z);
136  glVertex3d(x + 1, 0, z + 1);
137  glVertex3d(x, 0, z + 1);
138  }
139  }
140  glEnd();
141  glEndList();
142  }
GLfloat RED[]
Definition: openGL_bounce.c:13
GLfloat WHITE[]
Definition: openGL_bounce.c:12

References depth, displayListId, RED, WHITE, and width.

Referenced by init().

◆ draw()

void Checkerboard::draw ( )
inline

Definition at line 144 of file openGL_bounce.c.

144  {
145  glCallList(displayListId);
146  }

References displayListId.

Referenced by display().

Member Data Documentation

◆ depth

int Checkerboard::depth
private

Definition at line 107 of file openGL_bounce.c.

Referenced by centerz(), and create().

◆ displayListId

int Checkerboard::displayListId
private

Definition at line 105 of file openGL_bounce.c.

Referenced by create(), and draw().

◆ width

int Checkerboard::width
private

Definition at line 106 of file openGL_bounce.c.

Referenced by centerx(), and create().


The documentation for this class was generated from the following file: