void draw(void) { int x, y; double diff; glBegin(GL_QUADS); GLfloat c1[4] = { 0, 0, 1, 1 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, c1); VERTEX3(0, 0, waterh); VERTEX3(0, maph - 1, waterh); VERTEX3(mapw - 1, maph - 1, waterh); VERTEX3(mapw - 1, 0, waterh); GLfloat c2[4] = { 34 / 255., 139 / 255., 34 / 255., 1 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, c2); for(x = 0; x < mapw - 1; ++x) for(y = 0; y < maph - 1; ++y) { diff = HEIGHT(x, y) - HEIGHT(x + 1, y + 1); glNormal3f(diff, diff, 2); VERTEX2(x, y); VERTEX2(x, y + 1); VERTEX2(x + 1, y + 1); VERTEX2(x + 1, y); } GLfloat c3[4] = { 160 / 255., 82 / 255., 45 / 255., 1 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, c3); glNormal3i(0, -1, 0); for(x = 0; x < mapw - 1; ++x) { VERTEX3(x, 0, waterh); VERTEX2(x, 0); VERTEX2(x + 1, 0); VERTEX3(x + 1, 0, waterh); } glNormal3i(1, 0, 0); for(y = 0; y < maph - 1; ++y) { VERTEX3(mapw - 1, y, waterh); VERTEX2(mapw - 1, y); VERTEX2(mapw - 1, y + 1); VERTEX3(mapw - 1, y + 1, waterh); } glNormal3i(0, 1, 0); for(x = 0; x < mapw - 1; ++x) { VERTEX3(x, maph - 1, waterh); VERTEX3(x + 1, maph - 1, waterh); VERTEX2(x + 1, maph - 1); VERTEX2(x, maph - 1); } glNormal3i(-1, 0, 0); for(y = 0; y < maph - 1; ++y) { VERTEX3(0, y, waterh); VERTEX3(0, y + 1, waterh); VERTEX2(0, y + 1); VERTEX2(0, y); } glEnd(); }
void drawStripes(void) { GLfloat stripeColor[4] = {1, 1, 0, 1}; int i; float stripeLength; stripeLength = (16 - stripeGap * (numStripes - 1)) / numStripes; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, stripeColor); glBegin(GL_QUADS); glNormal3i(0, 1, 0); glVertex3f(4.5, 0, 8.5); glVertex3f(4.5, 0, -8.5); glVertex3f(3.5, 0, -8.5); glVertex3f(3.5, 0, 8.5); glVertex3f(-3.5, 0, 8.5); glVertex3f(-3.5, 0, -8.5); glVertex3f(-4.5, 0, -8.5); glVertex3f(-4.5, 0, 8.5); for(i = 0; i < numStripes; i++) { glVertex3f(.5, 0, 8 - i * (stripeLength + stripeGap)); glVertex3f(.5, 0, 8 - i * (stripeLength + stripeGap) - stripeLength); glVertex3f(-.5, 0, 8 - i * (stripeLength + stripeGap) - stripeLength); glVertex3f(-.5, 0, 8 - i * (stripeLength + stripeGap)); } glEnd(); }
// Une fonction pour afficher une boite à l'aide d'OpenGL void Cursor::drawKapla(unsigned int x, unsigned int y,unsigned int z) { glPushMatrix(); glTranslatef(m_x,20,m_y); glScalef(x,y,z); glBegin (GL_QUADS); //face 1 glNormal3i(-1, 1,-1); glVertex3i(-1, 1,-1); glVertex3i( 1, 1,-1); glVertex3i( 1,-1,-1); glVertex3i(-1,-1,-1); //face 2 glNormal3i(-1,-1,-1); glVertex3i(-1,-1,-1); glVertex3i( 1,-1,-1); glVertex3i( 1,-1, 1); glVertex3i(-1,-1, 1); // face 3 glNormal3i( 1,-1, 1); glVertex3i( 1,-1, 1); glVertex3i( 1,-1,-1); glVertex3i( 1, 1,-1); glVertex3i( 1, 1, 1); //face 4 glNormal3i( 1, 1,-1); glVertex3i( 1, 1,-1); glVertex3i(-1, 1,-1); glVertex3i(-1, 1, 1); glVertex3i( 1, 1, 1); //face 5 glNormal3i(-1, 1, 1); glVertex3i(-1, 1, 1); glVertex3i(-1, 1,-1); glVertex3i(-1,-1,-1); glVertex3i(-1,-1, 1); //face 6 glNormal3i( 1,-1, 1); glVertex3i( 1,-1, 1); glVertex3i( 1, 1, 1); glVertex3i(-1, 1, 1); glVertex3i(-1,-1, 1); glEnd(); glPopMatrix(); }
void box(int x, int y,int z) { glPushMatrix(); glScalef(x,y,z); glBegin (GL_QUADS); //face 1 glNormal3i(-1, 1,-1); glVertex3i(-1, 1,-1); glVertex3i( 1, 1,-1); glVertex3i( 1,-1,-1); glVertex3i(-1,-1,-1); //face 2 glNormal3i(-1,-1,-1); glVertex3i(-1,-1,-1); glVertex3i( 1,-1,-1); glVertex3i( 1,-1, 1); glVertex3i(-1,-1, 1); // face 3 glNormal3i( 1,-1, 1); glVertex3i( 1,-1, 1); glVertex3i( 1,-1,-1); glVertex3i( 1, 1,-1); glVertex3i( 1, 1, 1); //face 4 glNormal3i( 1, 1,-1); glVertex3i( 1, 1,-1); glVertex3i(-1, 1,-1); glVertex3i(-1, 1, 1); glVertex3i( 1, 1, 1); //face 5 glNormal3i(-1, 1, 1); glVertex3i(-1, 1, 1); glVertex3i(-1, 1,-1); glVertex3i(-1,-1,-1); glVertex3i(-1,-1, 1); //face 6 glNormal3i( 1,-1, 1); glVertex3i( 1,-1, 1); glVertex3i( 1, 1, 1); glVertex3i(-1, 1, 1); glVertex3i(-1,-1, 1); glEnd(); glPopMatrix(); }
void drawAsphalt(void) { GLfloat asphaltColor[4] = {.25, .25, .25, 1}; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, asphaltColor); glBegin(GL_QUADS); glNormal3i(0, 1, 0); glVertex3f(5, 0, 9.5); glVertex3f(5, 0, -9.5); glVertex3f(-5, 0, -9.5); glVertex3f(-5, 0, 9.5); glEnd(); }
void drawGround(void) { GLfloat groundColor[4] = {.647, .165, .165, 1}; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, groundColor); glBegin(GL_QUADS); glNormal3i(0, 1, 0); glVertex3f(10, 0, 10); glVertex3f(10, 0, -10); glVertex3f(-10, 0, -10); glVertex3f(-10, 0, 10); glEnd(); }
/* * Draw the room */ void display(void) { GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 }; GLuint texture; /* Floor properties */ GLfloat floor_diffuse[] = { 0.2, 0.5, 0.8, 1.0 }; GLfloat floor_ambient[] = { 1, 1, 1, 1.0 }; GLfloat floor_specular[] = { 0.2, 0.5, 0.8, 1.0 }; GLfloat high_shininess[] = { 100.0 }; /* Trunk & branch properties */ GLfloat wood_diffuse[] = { 0.5, 0.7, 0.1, 1.0 }; GLfloat wood_ambient[] = { 1, 1, 1, 1 }; GLfloat wood_specular[] = { 0.5, 0.7, 0.1, 1.0 }; /* Clear the output color buffer) */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Get texture */ texture = LoadTextureRAW("grass-tile.bmp", 1); glBindTexture( GL_TEXTURE_2D, texture ); /* Floor */ glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, floor_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, floor_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, floor_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, high_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_mat); glBegin(GL_POLYGON); glTexCoord2f(TEX_SCALE, TEX_SCALE); glNormal3i(0, 1, 0); glVertex3i(-100, 0, -100); glTexCoord2f(TEX_SCALE, 0); glNormal3i(0, 1, 0); glVertex3i(25, 0, -100); glTexCoord2f(0, 0); glNormal3i(0, 1, 0); glVertex3i(25, 0, 25); glTexCoord2f(0, TEX_SCALE); glNormal3i(0, 1, 0); glVertex3i(-100, 0, 25); glEnd(); glPopMatrix(); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, wood_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, wood_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, wood_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, high_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_mat); glPopMatrix(); for(int i=0; i < NUM_TREES; i++) { float x = trees[i].x; float y = trees[i].y; float z = trees[i].z; #ifdef DEBUG printf("[%2.0d] x, y, z = %0.2f, %2.0f, %0.2f\n", i, x, y, z); #endif glPushMatrix(); glTranslatef(x, 0.0, z); glRotatef(-90.0, 1.0, 0.0, 0.0); glutSolidCone(0.3, y, 60, 40); glPopMatrix(); } glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, wood_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, wood_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, wood_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, high_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_mat); glPopMatrix(); glutSwapBuffers(); glDeleteTextures( 1, &texture ); }
template< > inline void glNormal3< int > (int nx,int ny,int nz ) { glNormal3i(nx,ny,nz); };
///////////////////////////////////////////////////////// // Render // void GEMglNormal3i :: render(GemState *state) { glNormal3i (nx, ny, nz); }
inline void glNormal(Vector2i const &v, int &z) { glNormal3i(v.c[0], v.c[1], z); }
void World::draw(){ double halfWidth = width/2; double halfHeight = height/2; glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(2,2); glBegin(GL_QUADS); //Back side glNormal3i(0, 1, 0); glTexCoord2f(0.33, 0); glVertex3f(-halfWidth, -halfHeight, 0.0f); glTexCoord2f(0.33, 0.33); glVertex3f(-halfWidth, -halfHeight, HIGH); glTexCoord2f(0.66, 0.33); glVertex3f(halfWidth, -halfHeight, HIGH); glTexCoord2f(0.66, 0); glVertex3f(halfWidth, -halfHeight, 0.0f); //Left side glNormal3i(1, 0, 0); glTexCoord2f(0, 0.66); glVertex3f(-halfWidth, halfHeight, 0.0f); glTexCoord2f(0.33, 0.66); glVertex3f(-halfWidth, halfHeight, HIGH); glTexCoord2f(0.33, 0.33); glVertex3f(-halfWidth, -halfHeight, HIGH); glTexCoord2f(0, 0.33); glVertex3f(-halfWidth, -halfHeight, 0.0f); //Right side glNormal3i(-1, 0, 0); glTexCoord2d(1, 0.33); glVertex3f(halfWidth, -halfHeight, 0.0f); glTexCoord2d(0.66, 0.33); glVertex3f(halfWidth, -halfHeight, HIGH); glTexCoord2d(0.66, 0.66); glVertex3f(halfWidth, halfHeight, HIGH); glTexCoord2d(1, 0.66); glVertex3f(halfWidth, halfHeight, 0.0f); //Front side glNormal3i(0, -1, 0); glTexCoord2d(0.66, 1); glVertex3f(halfWidth, halfHeight, 0.0f); glTexCoord2d(0.66, 0.66); glVertex3f(halfWidth, halfHeight, HIGH); glTexCoord2d(0.33, 0.66); glVertex3f(-halfWidth, halfHeight, HIGH); glTexCoord2d(0.33, 1); glVertex3f(-halfWidth, halfHeight, 0.0f); //Top side glNormal3i(0, 0, -1); glTexCoord2d(0.66, 0.66); glVertex3f(halfWidth, halfHeight, HIGH); glTexCoord2d(0.66, 0.33); glVertex3f(halfWidth, -halfHeight, HIGH); glTexCoord2d(0.33, 0.33); glVertex3f(-halfWidth, -halfHeight, HIGH); glTexCoord2d(0.33, 0.66); glVertex3f(-halfWidth, halfHeight, HIGH); glEnd(); glPolygonOffset(0,0); glDisable(GL_POLYGON_OFFSET_FILL); }
/* Function: loadLevel * Parameters: char* filename * Loads the level specified by filename into the board array, * loads the ghost shortest path home board into the ghostSPHome * array, sets up initial player positions and generates a display * list to draw the maze walls */ void loadLevel(char* filename) { int i, j, x, y; int wallColorv[3]; int readGhostboard = 0; char lineChar = '0'; FILE* handle; /* Reset some global variables */ boardHeight = 0; boardWidth = 0; pellets = 0; superPellets = 0; handle = fopen(filename, "r"); if (handle == NULL) { printf("Could not open board file: %s\n", filename); exit(1); } /* Read level wall colours */ fscanf(handle, "%d", &(wallColorv[0])); fscanf(handle, "%d", &(wallColorv[1])); fscanf(handle, "%d", &(wallColorv[2])); fscanf(handle, "%c", &lineChar); /* Scan file to determine board width and height */ while (!feof(handle)) { fscanf(handle, "%c", &lineChar); /* If end of board layout */ if (lineChar == 'Z') break; while(lineChar != '\n' && !feof(handle)) { if (boardHeight == 0) boardWidth++; fscanf(handle, "%c", &lineChar); } boardHeight++; } rewind(handle); /* Read level wall colours again */ fscanf(handle, "%d", &(wallColorv[0])); fscanf(handle, "%d", &(wallColorv[1])); fscanf(handle, "%d", &(wallColorv[2])); fscanf(handle, "%c", &lineChar); /* Read level into array, set pacman/ghost starting positions */ for (j = 0; j < boardHeight; j++) { for (i = 0; i < boardWidth; i++) { fscanf(handle, "%c", &lineChar); if (lineChar == 'S') { pacman.startY = boardHeight - j; pacman.startX = i; } if (lineChar == 'g') { ghosts[0].startY = boardHeight - j + 2; ghosts[0].startX = i + 1; ghosts[1].startY = boardHeight - j; ghosts[1].startX = i; ghosts[2].startY = boardHeight - j; ghosts[2].startX = i + 1; ghosts[3].startY = boardHeight - j; ghosts[3].startX = i + 2; } if (lineChar == '.') pellets++; if (lineChar == 'P') superPellets++; board[j][i] = lineChar; } fscanf(handle, "%c", &lineChar); /* read EOL (\n) char */ } fscanf(handle, "%c", &lineChar); /* read Z char */ fscanf(handle, "%c", &lineChar); /* read EOL (\n) char */ /* Read ghost shortest path home into array */ for (j = 0; j < boardHeight; j++) { for (i = 0; i < boardWidth; i++) { fscanf(handle, "%c", &lineChar); ghostSPHome[j][i] = lineChar; } fscanf(handle, "%c", &lineChar); /* read EOF (\n) char */ } fclose(handle); /* Setup ghosts/pacman attributes */ playerSetup(1); /* Generate display list for the walls */ walls = glGenLists(1); glNewList(walls, GL_COMPILE); for (y = 0; y < boardHeight; y++) { for (x = 0; x < boardWidth; x++) { if (board[y][x] == '#') { glBegin(GL_QUADS); glColor3f(wallColorv[0] / 255.0, wallColorv[1] / 255.0, wallColorv[2] / 255.0); /* top */ glNormal3i(0, 0, 1); glVertex3f((GLfloat)x, boardHeight - (GLfloat)y, wallHeight); glVertex3f((GLfloat)x + 1.0, boardHeight - (GLfloat)y, wallHeight); glVertex3f((GLfloat)x + 1.0, boardHeight - ((GLfloat)y + 1.0), wallHeight); glVertex3f((GLfloat)x, boardHeight - ((GLfloat)y + 1.0), wallHeight); /* left side */ glNormal3i(-1, 0, 0); glVertex3f((GLfloat)x, boardHeight - (GLfloat)y, 0.0); glVertex3f((GLfloat)x, boardHeight - (GLfloat)y, wallHeight); glVertex3f((GLfloat)x, boardHeight - ((GLfloat)y + 1.0), wallHeight); glVertex3f((GLfloat)x, boardHeight - ((GLfloat)y + 1.0), 0.0); /* right side */ glNormal3i(0, 1, 0); glVertex3f((GLfloat)x + 1.0, boardHeight - (GLfloat)y, 0.0); glVertex3f((GLfloat)x + 1.0, boardHeight - (GLfloat)y, wallHeight); glVertex3f((GLfloat)x + 1.0, boardHeight - ((GLfloat)y + 1.0), wallHeight); glVertex3f((GLfloat)x + 1.0, boardHeight - ((GLfloat)y + 1.0), 0.0); /* front */ glNormal3i(0, -1, 0); glVertex3f((GLfloat)x, boardHeight - (GLfloat)y, 0.0); glVertex3f((GLfloat)x + 1.0, boardHeight - (GLfloat)y, 0.0); glVertex3f((GLfloat)x + 1.0, boardHeight - (GLfloat)y, wallHeight); glVertex3f((GLfloat)x, boardHeight - (GLfloat)y, wallHeight); /* back */ glNormal3i(0, 1, 0); glVertex3f((GLfloat)x, boardHeight - ((GLfloat)y + 1.0), 0.0); glVertex3f((GLfloat)x + 1.0, boardHeight - ((GLfloat)y + 1.0), 0.0); glVertex3f((GLfloat)x + 1.0, boardHeight - ((GLfloat)y + 1.0), wallHeight); glVertex3f((GLfloat)x, boardHeight - ((GLfloat)y + 1.0), wallHeight); glEnd(); } } } glEndList(); }
inline void glNormal( const GLint & x, const GLint & y, const GLint & z ) { glNormal3i( x, y, z ); }
M(void, glNormal3i, jint nx, jint ny, jint nz) { glNormal3i(nx, ny, nz); }