/********************************************************************* * * * FLY * * --E#Y#E-- * * ===MUSCLE=== * * * *********************************************************************/ /* Header Files */ #include "cockpit.h" /*---------------------------------------------------------------------------*/ /* Buffer */ GLuint vbos2[MAX_BUFFERS]; /*-------------------------------------------------------------------------*/ /* Init Color */ struct c_color { float r; float g; float b; float a; }c1, n1; /* Textures Coordinate */ struct c_texture { float s; float t; float p; float q; }c2, n2; /* Init Triangles */ struct c_triangles { float x; float y; float z; float w; }c3, n3; /* Structure Float */ struct c_float { struct c_color col; struct c_texture tex; struct c_triangles tra; }fl; /*-------------------------------------------------------------------------*/ /* Vector */ GLfloat vcolor2[BV]; GLfloat tcircle2[BV]; GLfloat vcircle2[BV]; /* Buffer */ GLfloat n_colors[BV]; GLfloat n_texCoords[BV]; GLfloat n_vertices[BV]; /* Index */ GLuint n_indices[BV]; /*---------------------------------------------------------------------------*/ /* Shader Program */ unsigned int n_shaderProgram; /*---------------------------------------------------------------------------*/ /* Cockpit Files */ const char pointFile[] = "DATA/points.fs"; const char metalicFile[] = "DATA/metalic.fs"; const char cockpitFile[] = "DATA/cockpit.fs"; const char rasterWhite[] = "DATA/raster-white.fs"; const char rasterBlue[] = "DATA/raster-blue.fs"; /*---------------------------------------------------------------------------*/ /* Shader Language */ char textureShader2() { static const GLchar vert[] = "GLSL/fly.vert"; static const GLchar frag[] = "GLSL/fly.frag"; /* Create GLSL Shaders / Compile Shaders */ createShader(vert, frag); createProgram(n_shaderProgram); /* Init */ Location(n_shaderProgram, 0, "a_Vertex"); Location(n_shaderProgram, 1, "a_TexCoord"); Location(n_shaderProgram, 2, "a_Color"); /* Re link the program */ linkProgram(n_shaderProgram); bindShader(n_shaderProgram); /*------------------------------------------------------------------*/ /* Matrix */ static float modelview2[ID]; static float projection2[ID]; /* Passing Data */ glGetFloatv(GL_PROJECTION_MATRIX, projection2); glGetFloatv(GL_MODELVIEW_MATRIX, modelview2); /* Matrix */ Uniform4x4(n_shaderProgram, "projection_matrix", 0, projection2); Uniform4x4(n_shaderProgram, "modelview_matrix", 1, modelview2); return TRUE; } /*---------------------------------------------------------------------------*/ /* Buffer Init */ char initCockpit() { glGenBuffers = (PFNGLGENBUFFERSARBPROC)glXGetProcAddress ((const GLubyte*)"glGenBuffers"); glBindBuffer = (PFNGLBINDBUFFERPROC)glXGetProcAddress ((const GLubyte*)"glBindBuffer"); glBufferData = (PFNGLBUFFERDATAPROC)glXGetProcAddress ((const GLubyte*)"glBufferData"); /* Buffer */ if(!glGenBuffers || !glBindBuffer || !glBufferData) { printf("VBO: NOT SUPPORTED \n"); } /*------------------------------------------------------------------*/ #if SLOW_COMPUTER /* Initialize the Shader */ if(!textureShader2()) { printf(" COULD NOT INITIALIZE THE SHADER \n"); return FALSE; } #endif /*------------------------------------------------------------------*/ #if COCKPIT_VECTOR GridRaster(pointFile); /*GridRaster(metalicFile);*/ GridRaster(cockpitFile); GridRaster(rasterWhite); GridRaster(rasterBlue); #endif /*------------------------------------------------------------------*/ /* Create Color Buffer */ glGenBuffers(MAX_BUFFERS, &vbos2[0]); glBindBuffer(GL_ARRAY_BUFFER, vbos2[COLOR_BUFFER]); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 4 * BV, &n_colors[0], GL_STATIC_DRAW); /* Create Texture Buffer */ glBindBuffer(GL_ARRAY_BUFFER, vbos2[NORMAL_BUFFER]); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 2 * BV, &n_texCoords[0], GL_STATIC_DRAW); /* Create Vertex Buffer */ glBindBuffer(GL_ARRAY_BUFFER, vbos2[VERTEX_BUFFER]); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * BV, &n_vertices[0], GL_STATIC_DRAW); /*------------------------------------------------------------------*/ /* Create Element Buffer */ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos2[INDEX_BUFFER]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * 3 * BV, &n_indices[0], GL_STATIC_DRAW); return TRUE; } /*---------------------------------------------------------------------------*/ /* X / Y / Z / W */ float C_Vertex(float cx, float cy, float cz) { float vcircle2[3]; vcircle2[0] = 0; vcircle2[1] = 0; vcircle2[2] = 0; vcircle2[0] = cx; vcircle2[1] = cy; vcircle2[2] = cz; return *vcircle2; } /*---------------------------------------------------------------------------*/ /* R / G / B / A */ float C_Color(float cr, float cg, float cb, float ca) { float vcolor2[4]; vcolor2[0] = 0; vcolor2[1] = 0; vcolor2[2] = 0; vcolor2[3] = 0; vcolor2[0] = cr; vcolor2[1] = cg; vcolor2[2] = cb; vcolor2[3] = ca; return *vcolor2; } /*---------------------------------------------------------------------------*/ /* S / T / P / Q */ float C_Textur(float cs, float ct) { float tcircle2[2]; tcircle2[0] = 0; tcircle2[1] = 0; tcircle2[0] = cs; tcircle2[1] = ct; return *tcircle2; } /*---------------------------------------------------------------------------*/ /* Render Raster */ void GridRaster(const char *nFile) { /* Load File */ int w = 0; FILE *rast; rast=fopen(nFile,"r"); /* Grid File */ while(fscanf(rast,"%f %f %f %f %f %f %f %f %f", &fl.col.r, &fl.col.g, &fl.col.b, &fl.col.a, &fl.tex.s, &fl.tex.t, &fl.tra.x, &fl.tra.y, &fl.tra.z) != EOF) { #if COCKPIT_VECTOR /* VERTEX */ C_Color(fl.col.r, fl.col.g, fl.col.b, fl.col.a); C_Textur(fl.tex.s, fl.tex.t); C_Vertex(fl.tra.x, fl.tra.y, fl.tra.z); /* ELEMENTS */ n_indices[w++]; n_indices[w++]; n_indices[w++]; #else /* ARRAY */ glColor4f(fl.col.r, fl.col.g, fl.col.b, fl.col.a); glTexCoord2f(fl.tex.s, fl.tex.t); glVertex3f(fl.tra.x, fl.tra.y, fl.tra.z); #endif } /* Close File */ fclose(rast); } /*---------------------------------------------------------------------------*/ /* Polygon Mode */ void PolygonMatrix(const GLenum mode, const GLenum front, const char *nFile) { glPolygonMode(GL_FRONT_AND_BACK, front); glBegin(mode); GridRaster(nFile); glEnd(); } /*---------------------------------------------------------------------------*/ /* Draw Arrays */ void DrawMatrix(const GLenum mode, const GLenum front, const GLint count, const GLint offset) { glPolygonMode(GL_FRONT_AND_BACK, front); glPushMatrix(); #if DRAW_ELEMENTS glDrawElements(mode, count, GL_UNSIGNED_INT, 0); #else glDrawArrays(mode, offset, count); #endif glPopMatrix(); } /*---------------------------------------------------------------------------*/ /* Render Cockpit */ void renderCockpit() { /* Primitive */ const GLenum modeP = GL_POINTS; const GLenum modeL = GL_LINES; const GLenum modeT = GL_TRIANGLES; const GLenum modeQ = GL_QUADS; /* Mode */ const GLenum frontP = GL_POINT; const GLenum frontL = GL_LINE; const GLenum frontF = GL_FILL; /* Enable Anti-aliasing */ glEnable(GL_POINT_SMOOTH); glLineWidth(1.0); #if COCKPIT_VECTOR /* Offset */ const GLint offsetP = 0; /* 20 */ const GLint offsetT = 75; /* 75 */ const GLint offsetE = 0; /* 55 */ const GLint offsetQ = 0; /* 55 */ const GLint offsetR = 600; /* 645 */ /* Count */ const GLint countP = 16; /* 20 */ const GLint countT = 90; /* 75 */ const GLint countE = 145; /* 55 */ const GLint countQ = 200; /* 55 */ const GLint countR = 600; /* 645 */ /* Draw Cockpit */ glPointSize(15.0); DrawMatrix(modeP, frontP, countP, offsetP); /*DrawMatrix(modeT, frontF, countT, offsetT);*/ DrawMatrix(modeQ, frontL, countQ, offsetQ); DrawMatrix(modeQ, frontF, countE, offsetE); /* Draw Raster */ glPointSize(5.0); DrawMatrix(modeQ, frontP, countR, offsetR); DrawMatrix(modeQ, frontL, countR, offsetR); DrawMatrix(modeQ, frontF, countR, offsetR); #else /* Polygon Cockpit */ glPointSize(15.0); PolygonMatrix(modeP, frontP, pointFile); PolygonMatrix(modeT, frontF, metalicFile); PolygonMatrix(modeQ, frontL, cockpitFile); PolygonMatrix(modeQ, frontF, cockpitFile); /* Polygon Raster */ glPointSize(5.0); PolygonMatrix(modeQ, frontP, rasterWhite); PolygonMatrix(modeQ, frontL, rasterWhite); PolygonMatrix(modeQ, frontF, rasterBlue); #endif /* Disable Anti-aliasing */ glDisable(GL_POINT_SMOOTH); glFlush(); } /*---------------------------------------------------------------------------*/ /* Render Cockpit */ void Cockpit() { /* PlaneView */ CameraLook(); ScalePlane(); TransPlane(); /* Shader Program */ linkProgram(n_shaderProgram); /* Re link the program */ bindShader(n_shaderProgram); /* Enable our shader */ /*------------------------------------------------------------------*/ /* Active Texture */ /*glActiveTextureARB(GL_TEXTURE5_ARB);*/ /*glClientActiveTextureARB(GL_TEXTURE5_ARB);*/ /* Attrib Array */ /*glEnableVertexAttribArrayARB(0);*/ /*glEnableVertexAttribArrayARB(1);*/ /*glEnableVertexAttribArrayARB(2);*/ /* Vertex Array */ glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); /*------------------------------------------------------------------*/ glBindBuffer(GL_ARRAY_BUFFER, vbos2[COLOR_BUFFER]); /* Color */ const GLint csize = 4; /* ( R, G, B, A) */ const GLenum ctype = GL_FLOAT; /* the data is 8bit unsigned values */ const GLboolean cnormalize = GL_TRUE; /* normalize the data (convert from 0-255 to 0-1) */ const GLsizei cstride = 0; /* 0 = move forward size * sizeof(type) */ const GLbyte coffset = 0; /* start at the beginning of the buffer */ glColorPointer(csize, ctype, cstride, &vcolor2[coffset]); /*glVertexAttribPointerARB((GLuint)2, csize, ctype, cnormalize, cstride, &vcolor2[coffset]);*/ /*------------------------------------------------------------------*/ glBindBuffer(GL_ARRAY_BUFFER, vbos2[VERTEX_BUFFER]); /* Vertex */ const GLint vsize = 3; /* ( X, Y, Z, W ) */ const GLenum vtype = GL_FLOAT; const GLboolean vnormalize = GL_FALSE; const GLsizei vstride = 0; const GLbyte voffset = 0; glVertexPointer(vsize, vtype, vstride, &vcircle2[voffset]); /*glVertexAttribPointerARB((GLuint)0, vsize, vtype, vnormalize, vstride, &vcircle2[voffset]);*/ /*------------------------------------------------------------------*/ glBindBuffer(GL_ARRAY_BUFFER, vbos2[NORMAL_BUFFER]); /* Texture */ const GLint tsize = 2; /* ( S, T, P, Q ) */ const GLenum ttype = GL_FLOAT; const GLboolean tnormalize = GL_FALSE; const GLsizei tstride = 0; const GLbyte toffset = 0; glTexCoordPointer(tsize, ttype, tstride, &tcircle2[toffset]); /*glVertexAttribPointerARB((GLuint)1, tsize, ttype, tnormalize, tstride, &tcircle2[toffset]);*/ /*------------------------------------------------------------------*/ /* Render Cockpit */ renderCockpit(); /*------------------------------------------------------------------*/ /* Disable Client State */ glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); /* Disable Array */ /*glDisableVertexAttribArrayARB(2);*/ /*glDisableVertexAttribArrayARB(1);*/ /*glDisableVertexAttribArrayARB(0);*/ /* Active Texture 0 */ /*glActiveTextureARB(GL_TEXTURE0_ARB);*/ /*glClientActiveTextureARB(GL_TEXTURE0_ARB);*/ /*------------------------------------------------------------------*/ /* Delete Buffer */ glDeleteBuffers(MAX_BUFFERS, &vbos2[0]); /* Delete Shader */ DeleteShader(n_shaderProgram); } /*---------------------------------------------------------------------------*/