void LoadManTextures() { man_tex = TextureLoad("textures/security.bmp", GL_FALSE, GL_LINEAR, GL_LINEAR, GL_REPEAT); man_face_tex = TextureLoad("textures/face.bmp", GL_FALSE, GL_LINEAR, GL_LINEAR, GL_REPEAT); quadric = gluNewQuadric(); gluQuadricNormals(quadric, GLU_SMOOTH); gluQuadricTexture(quadric, GL_TRUE); }
Terrain::Terrain(unsigned int dimensionIn, float heightIn) { this->dimension = dimensionIn; this->perlin_data = new float[this->dimension * this->dimension]; this->height = heightIn; TextureLoad(); Vertex* aoVertices = new Vertex[this->dimension*this->dimension]; for (unsigned int r = 0; r < this->dimension; ++r) { for (unsigned int c = 0; c < this->dimension; ++c) { float hp = perlin_data[r*this->dimension + c] * height; aoVertices[r * this->dimension + c].position = vec4((float)c, hp, (float)r, 1); aoVertices[r*this->dimension + c].texCoord = vec2((float)r / this->dimension, (float)c / this->dimension); aoVertices[r * this->dimension + c].normal = vec4(normalize(vec3(1)), 0); aoVertices[r * this->dimension + c].normal.w = 1; if (c == 0 || r == 0 || c == this->dimension || r == this->dimension) { aoVertices[r * this->dimension + c].normal = vec4(0, 0, 0, 0); } else { vec3 c1 = aoVertices[r* this->dimension + c].position.xyz - aoVertices[(r - 1)* this->dimension + c].position.xyz; vec3 c2 = aoVertices[r* this->dimension + c].position.xyz - aoVertices[r * this->dimension + c - 1].position.xyz; vec3 d1 = glm::cross(c2, c1); aoVertices[r * this->dimension + c].normal.xyz = normalize(d1); aoVertices[r * this->dimension + c].normal.w = 1; } } } unsigned int* auiIndices = new unsigned int[(this->dimension - 1)*(this->dimension - 1) * 6]; unsigned int index = 0; for (unsigned int r = 0; r < (this->dimension - 1); ++r) { for (unsigned int c = 0; c < (this->dimension - 1); ++c) { //Tirangle 1 auiIndices[index++] = r*this->dimension + c; auiIndices[index++] = (r + 1)*this->dimension + c; auiIndices[index++] = (r + 1)*this->dimension + (c + 1); //Triangle 2 auiIndices[index++] = r*this->dimension + c; auiIndices[index++] = (r + 1)*this->dimension + (c + 1); auiIndices[index++] = r*this->dimension + (c + 1); } } glGenBuffers(1, &this->m_VBO); glGenBuffers(1, &this->m_IBO); glGenVertexArrays(1, &this->m_VAO); glBindVertexArray(this->m_VAO); //Vertex Buffer glBindBuffer(GL_ARRAY_BUFFER, this->m_VBO); glBufferData(GL_ARRAY_BUFFER, (this->dimension*this->dimension)*sizeof(Vertex), aoVertices, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(sizeof(vec4))); glVertexAttribPointer(2, 4, GL_FLOAT, GL_TRUE, sizeof(Vertex), (void*)(sizeof(vec4) + sizeof(vec2))); //Index Buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->m_IBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, (this->dimension - 1) * (this->dimension - 1) * 6 * sizeof(unsigned int), auiIndices, GL_STATIC_DRAW); //Vertex Array Object glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); delete[] aoVertices; delete[] auiIndices; }
int main(int argc, char **argv) { superBallSPositionX = 300; superBallSPositionY= 400; superBallSRadius = 80; superBallSSpeedX = 0.0f; superBallSSpeedY = 0.0f; glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); glutInitWindowSize( glutGet(GLUT_SCREEN_WIDTH),glutGet(GLUT_SCREEN_HEIGHT) ); glutInitWindowPosition(400,150); char* s = "Super Ball"; glutCreateWindow(s); screenWidth = glutGet(GLUT_WINDOW_WIDTH);//glutGet(GLUT_SCREEN_WIDTH); screenHeight = glutGet(GLUT_WINDOW_HEIGHT);//glutGet(GLUT_SCREEN_HEIGHT); phidgetManag = new PhidgetManager(); phidgetManag->start(); startgame(); //load the textures: //texture_bomb = LoadTexture("bomb.bmp"); texture_bomb = TextureLoad("bomb.bmp", GL_FALSE, /* I - Generate alpha for bitmap */ GL_LINEAR_MIPMAP_LINEAR, /* I - Minification filter */ GL_LINEAR, /* I - Magnification filter */ GL_REPEAT); /* glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); int imageWidth = 300; int imageHeight = 278; GLsizei sWidth, sHeight; sWidth = nearestPower( imageWidth ); sHeight = nearestPower( imageHeight ); imageData = (GLubyte *)malloc( sHeight*sWidth*4*sizeof( GLubyte ) ); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData); //the texture width and height must be a power of two glEnable( GL_TEXTURE_2D ); */ glutFullScreen(); glutTimerFunc(milliSecondsIntervalForSpawningNewSpaceObjects, spawnNewSpaceObjects, 0); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(MouseButton); glutMotionFunc(MouseMove); glutIdleFunc(spindisplay); glutSpecialFunc(specialKeys); glutKeyboardFunc(keyboard); //start_the_Thread_with_the_Socket_TCP_server(); glutMainLoop(); }
void BuildF16(void) { int i; /* Looping var */ GLUquadric *quadric; /* Quadric object */ #ifdef GLU_VERSION_1_2 GLUtesselator *tess; /* Tesselator object */ #else GLUtriangulatorObj *tess; #endif /* GLU_VERSION_1_2 */ static GLdouble wing[][5] = /* Main wing points */ { /* { x, y, z, s, t } */ { 0.25, 0.0, -1.0, 0.125, 0.0 }, { 0.45, 0.0, 0.0, 0.25, 0.4 }, { 1.65, 0.0, 0.8, 1.0, 0.8 }, { 1.65, 0.0, 1.2, 1.0, 1.0 }, { 0.35, 0.0, 1.2, 0.15, 1.0 }, { 0.35, 0.0, 2.4, 0.15, 2.0 }, { 0.25, 0.0, 2.4, 0.125, 2.0 }, { 0.25, 0.0, 2.0, 0.125, 1.5 }, { -0.25, 0.0, 2.0, -0.125, 1.5 }, { -0.25, 0.0, 2.4, -0.125, 2.0 }, { -0.35, 0.0, 2.4, -0.15, 2.0 }, { -0.35, 0.0, 1.2, -0.15, 1.0 }, { -1.65, 0.0, 1.2, -1.0, 1.0 }, { -1.65, 0.0, 0.8, -1.0, 0.8 }, { -0.45, 0.0, 0.0, -0.25, 0.4 }, { -0.25, 0.0, -1.0, -0.125, 0.0 } }; static GLdouble tail[][5] = /* Tail points */ { /* { x, y, z, s, t } */ { 0.0, 0.24, 0.5, 1.5, 0.0 }, { 0.0, 0.4, 1.1, 1.2, 0.1 }, { 0.0, 1.0, 2.0, 0.4, 1.0 }, { 0.0, 1.0, 2.4, 0.05, 1.0 }, { 0.0, 0.4, 2.1, 0.2, 0.1 }, { 0.0, 0.24, 2.1, 0.2, 0.0 } }; static GLdouble left_fin[][5] = /* Left fin points */ { /* { x, y, z, s, t } */ { -0.1, -0.1, 1.1, 0.0, 0.0 }, { -0.25, -0.3, 1.2, 1.0, 0.0 }, { -0.25, -0.3, 1.5, 1.0, 1.0 }, { -0.1, -0.1, 1.5, 1.0, 0.0 } }; static GLdouble right_fin[][5] = /* Right fin points */ { /* { x, y, z, s, t } */ { 0.1, -0.1, 1.1, 0.0, 0.0 }, { 0.25, -0.3, 1.2, 1.0, 0.0 }, { 0.25, -0.3, 1.5, 1.0, 1.0 }, { 0.1, -0.1, 1.5, 1.0, 0.0 } }; static GLdouble left_rolleron[][5] = /* Left rolleron points */ { /* { x, y, z, s, t } */ { -0.35, 0.0, 1.6, 0.0, 0.0 }, { -0.85, 0.0, 2.1, 1.0, 0.5 }, { -0.85, 0.0, 2.4, 1.0, 1.0 }, { -0.35, 0.0, 2.4, 0.0, 1.0 } }; static GLdouble right_rolleron[][5] = /* Right rolleron points */ { /* { x, y, z, s, t } */ { 0.35, 0.0, 1.6, 0.0, 0.0 }, { 0.85, 0.0, 2.1, 1.0, 0.5 }, { 0.85, 0.0, 2.4, 1.0, 1.0 }, { 0.35, 0.0, 2.4, 0.0, 1.0 } }; /* Load the texture images */ F16Texture[0] = TextureLoad("camoflage.bmp", GL_FALSE, GL_NEAREST, GL_NEAREST, GL_REPEAT); F16Texture[1] = TextureLoad("tail.bmp", GL_FALSE, GL_NEAREST, GL_NEAREST, GL_REPEAT); /* Then build the F-16 body */ F16Body = glGenLists(1); glNewList(F16Body, GL_COMPILE); glBindTexture(GL_TEXTURE_2D, F16Texture[0]); tess = gluNewTess(); gluTessCallback(tess, GLU_TESS_BEGIN, glBegin); gluTessCallback(tess, GLU_TESS_END, glEnd); gluTessCallback(tess, GLU_TESS_VERTEX, (void (CALLBACK *)())glu_vertex); quadric = gluNewQuadric(); gluQuadricTexture(quadric, GL_TRUE); /* Nose */ glColor3f(0.8, 0.8, 0.8); glPushMatrix(); glTranslatef(0.0, 0.0, -2.5); gluCylinder(quadric, 0.0, 0.25, 1.0, 20, 2); glPopMatrix(); /* Main fuselage */ glColor3f(0.8, 0.8, 0.8); glPushMatrix(); glTranslatef(0.0, 0.0, -1.5); gluCylinder(quadric, 0.25, 0.25, 3.5, 20, 2); glPopMatrix(); /* Main wing */ glColor3f(0.8, 0.8, 0.8); glNormal3f(0.0, 1.0, 0.0); gluTessBeginPolygon(tess, NULL); #ifdef GL_VERSION_1_2 gluTessBeginContour(tess); #endif /* GL_VERSION_1_2 */ for (i = 0; i < 16; i ++) gluTessVertex(tess, wing[i], wing[i]); #ifdef GL_VERSION_1_2 gluTessEndContour(tess); #endif /* GL_VERSION_1_2 */ gluTessEndPolygon(tess); /* Fins */ glColor3f(0.8, 0.8, 0.8); glNormal3f(-1.0, 0.0, 0.0); gluTessBeginPolygon(tess, NULL); #ifdef GL_VERSION_1_2 gluTessBeginContour(tess); #endif /* GL_VERSION_1_2 */ for (i = 0; i < 4; i ++) gluTessVertex(tess, left_fin[i], left_fin[i]); #ifdef GL_VERSION_1_2 gluTessEndContour(tess); #endif /* GL_VERSION_1_2 */ gluTessEndPolygon(tess); glColor3f(0.8, 0.8, 0.8); glNormal3f(1.0, 0.0, 0.0); gluTessBeginPolygon(tess, NULL); #ifdef GL_VERSION_1_2 gluTessBeginContour(tess); #endif /* GL_VERSION_1_2 */ for (i = 0; i < 4; i ++) gluTessVertex(tess, right_fin[i], right_fin[i]); #ifdef GL_VERSION_1_2 gluTessEndContour(tess); #endif /* GL_VERSION_1_2 */ gluTessEndPolygon(tess); /* Tail */ glBindTexture(GL_TEXTURE_2D, F16Texture[1]); glColor3f(0.8, 0.8, 0.8); glNormal3f(1.0, 0.0, 0.0); gluTessBeginPolygon(tess, NULL); #ifdef GL_VERSION_1_2 gluTessBeginContour(tess); #endif /* GL_VERSION_1_2 */ for (i = 0; i < 6; i ++) gluTessVertex(tess, tail[i], tail[i]); #ifdef GL_VERSION_1_2 gluTessEndContour(tess); #endif /* GL_VERSION_1_2 */ gluTessEndPolygon(tess); /* Don't texture any more of the body... */ glDisable(GL_TEXTURE_2D); /* Canopy */ glPushMatrix(); glColor4f(0.5, 0.5, 1.0, 0.75); glTranslatef(0.0, 0.2, -1.0); glScalef(1.0, 1.0, 0.65 / 0.15); gluSphere(quadric, 0.15, 6, 12); glPopMatrix(); /* Engine */ glPushMatrix(); /* Cowling */ glColor3f(0.1, 0.1, 0.1); glTranslatef(0.0, 0.0, 2.0); gluCylinder(quadric, 0.25, 0.15, 0.5, 20, 2); gluDisk(quadric, 0.0, 0.25, 20, 2); /* Exhaust */ glPushAttrib(GL_LIGHTING_BIT); glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION); glColor3f(0.5, 0.5, 1.0); gluCylinder(quadric, 0.2, 0.0, 0.3, 10, 2); glColor4f(0.25, 0.25, 1.0, 0.75); gluCylinder(quadric, 0.2, 0.1, 0.4, 10, 2); glPopAttrib(); glPopMatrix(); glEndList(); /* Now the left rolleron */ F16Rolleron[0] = glGenLists(1); glNewList(F16Rolleron[0], GL_COMPILE); glBindTexture(GL_TEXTURE_2D, F16Texture[0]); glColor3f(0.8, 0.8, 0.8); glNormal3f(0.0, 1.0, 0.0); gluTessBeginPolygon(tess, NULL); #ifdef GL_VERSION_1_2 gluTessBeginContour(tess); #endif /* GL_VERSION_1_2 */ for (i = 0; i < 4; i ++) gluTessVertex(tess, left_rolleron[i], left_rolleron[i]); #ifdef GL_VERSION_1_2 gluTessEndContour(tess); #endif /* GL_VERSION_1_2 */ gluTessEndPolygon(tess); glEndList(); /* And the right rolleron */ F16Rolleron[1] = glGenLists(1); glNewList(F16Rolleron[1], GL_COMPILE); glBindTexture(GL_TEXTURE_2D, F16Texture[0]); glColor3f(0.8, 0.8, 0.8); glNormal3f(0.0, 1.0, 0.0); gluTessBeginPolygon(tess, NULL); #ifdef GL_VERSION_1_2 gluTessBeginContour(tess); #endif /* GL_VERSION_1_2 */ for (i = 0; i < 4; i ++) gluTessVertex(tess, right_rolleron[i], right_rolleron[i]); #ifdef GL_VERSION_1_2 gluTessEndContour(tess); #endif /* GL_VERSION_1_2 */ gluTessEndPolygon(tess); glEndList(); gluDeleteQuadric(quadric); gluDeleteTess(tess); }
int /* O - Exit status */ main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { glutInit(&argc, argv); #ifdef BOOK_COVER glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH); #else glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); #endif /* BOOK_COVER */ glutInitWindowSize(792, 573); glutCreateWindow("Terrain Using Vertex Culling Extension"); glutDisplayFunc(Redraw); if (glutDeviceGet(GLUT_HAS_JOYSTICK)) glutJoystickFunc(Joystick, 200); glutKeyboardFunc(Keyboard); glutMotionFunc(Motion); glutMouseFunc(Mouse); glutReshapeFunc(Resize); glutSpecialFunc(Special); BuildF16(); LandTexture = TextureLoad("land.bmp", GL_FALSE, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT); SkyTexture = TextureLoad("sky.bmp", GL_FALSE, GL_LINEAR, GL_LINEAR, GL_CLAMP); LoadTerrain(36, -112); puts("QUICK HELP:"); puts(""); puts("ESC - Quit"); puts("',' - Slow down, '<' - Slowest"); puts("'.' - Speed up, '>' - Fastest"); puts("'3' - Toggle terrain"); puts("'a' - Toggle aircraft"); puts("'f' - Toggle fog"); puts("'l' - Toggle lighting"); puts("'s' - Toggle sky/clouds"); puts("'t' - Toggle texturing"); puts("'w' - Toggle water"); puts("'W' - Toggle wireframe"); printf("GL_EXTENSIONS = %s\n", glGetString(GL_EXTENSIONS)); if (strstr(glGetString(GL_EXTENSIONS), "EXT_cull_vertex") != NULL) { UseCullVertex = 1; glCullParameterfvEXT = wglGetProcAddress("glCullParameterfvEXT"); } else if (strstr(glGetString(GL_EXTENSIONS), "SGI_cull_vertex") != NULL) { UseCullVertex = 1; glCullParameterfvEXT = wglGetProcAddress("glCullParameterfvSGI"); } else UseCullVertex = 0; glutMainLoop(); return (0); }