/********************************************************************* * * * FLY * * --E#Y#E-- * * ===MUSCLE=== * * * *********************************************************************/ /* Header Files */ #include "cockpit.h" /* Class */ UNIFORM uniform2; TMFONT tmfont2; MOV mov2; MOD mod2; //-------------------------------------------------------------------------- /* 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 */ vector vcolor2; vector tcircle2; vector vcircle2; /* Buffer */ vector n_colors; vector n_texCoords; vector n_vertices; /* Index */ vector n_indices; //-------------------------------------------------------------------------- /* 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 */ bool MOD::textureShader2() { static const GLchar vert[] = "GLSL/fly.vert"; static const GLchar frag[] = "GLSL/fly.frag"; /* Create GLSL Shaders / Compile Shaders */ uniform2.createShader(vert, frag); uniform2.createProgram(n_shaderProgram); /* Init */ uniform2.Location(n_shaderProgram, 0, "a_Vertex"); uniform2.Location(n_shaderProgram, 1, "a_TexCoord"); uniform2.Location(n_shaderProgram, 2, "a_Color"); /* Re link the program */ uniform2.linkProgram(n_shaderProgram); uniform2.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 */ uniform2.Uniform4x4(n_shaderProgram, "projection_matrix", 0, projection2); uniform2.Uniform4x4(n_shaderProgram, "modelview_matrix", 1, modelview2); return true; } //-------------------------------------------------------------------------- /* Buffer Init */ bool MOD::initCockpit() { glGenBuffers = (PFNGLGENBUFFERSARBPROC)glXGetProcAddress ((const GLubyte*)"glGenBuffers"); glBindBuffer = (PFNGLBINDBUFFERPROC)glXGetProcAddress ((const GLubyte*)"glBindBuffer"); glBufferData = (PFNGLBUFFERDATAPROC)glXGetProcAddress ((const GLubyte*)"glBufferData"); /* Buffer */ if(!glGenBuffers || !glBindBuffer || !glBufferData) { std::cerr << " VBO: NOT SUPPORTED " << std::endl; } //------------------------------------------------------------------- #if SLOW_COMPUTER /* Initialize the Font */ if(!tmfont2.initFont()) { std::cerr << " COULD NOT INITIALIZE THE FONT " << std::endl; return false; } /* Initialize the Shader */ if(!mod2.textureShader2()) { std::cerr << " COULD NOT INITIALIZE THE SHADER " << std::endl; return false; } #endif //------------------------------------------------------------------- #if COCKPIT_VECTOR mod2.GridRaster(pointFile); //mod2.GridRaster(metalicFile); mod2.GridRaster(cockpitFile); mod2.GridRaster(rasterWhite); mod2.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 MOD::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 MOD::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 MOD::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 MOD::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 */ n_colors.push_back(M_Color(fl.col.r, fl.col.g, fl.col.b, fl.col.a)); n_texCoords.push_back(M_Textur(fl.tex.s, fl.tex.t)); n_vertices.push_back(M_Vertex(fl.tra.x, fl.tra.y, fl.tra.z)); /* ELEMENTS */ n_indices.push_back(w++); n_indices.push_back(w++); n_indices.push_back(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 MOD::PolygonMatrix(const GLenum mode, const GLenum front, const char *nFile) { glPolygonMode(GL_FRONT_AND_BACK, front); glBegin(mode); mod2.GridRaster(nFile); glEnd(); } //-------------------------------------------------------------------------- /* Draw Arrays */ void MOD::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 MOD::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); mod2.DrawMatrix(modeP, frontP, countP, offsetP); //mod2.DrawMatrix(modeT, frontF, countT, offsetT); mod2.DrawMatrix(modeQ, frontL, countQ, offsetQ); mod2.DrawMatrix(modeQ, frontF, countE, offsetE); /* Draw Raster */ glPointSize(5.0); mod2.DrawMatrix(modeQ, frontP, countR, offsetR); mod2.DrawMatrix(modeQ, frontL, countR, offsetR); mod2.DrawMatrix(modeQ, frontF, countR, offsetR); #else /* Polygon Cockpit */ glPointSize(15.0); mod2.PolygonMatrix(modeP, frontP, pointFile); mod2.PolygonMatrix(modeT, frontF, metalicFile); mod2.PolygonMatrix(modeQ, frontL, cockpitFile); mod2.PolygonMatrix(modeQ, frontF, cockpitFile); /* Polygon Raster */ glPointSize(5.0); mod2.PolygonMatrix(modeQ, frontP, rasterWhite); mod2.PolygonMatrix(modeQ, frontL, rasterWhite); mod2.PolygonMatrix(modeQ, frontF, rasterBlue); #endif /* Disable Anti-aliasing */ glDisable(GL_POINT_SMOOTH); glFlush(); } //-------------------------------------------------------------------------- /* Render Motor */ void MOD::Cockpit() { /* PlaneView */ mov2.CameraLook(); mov2.ScalePlane(); mov2.TransPlane(); /* Shader Program */ uniform2.linkProgram(n_shaderProgram); // Re link the program uniform2.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]); //------------------------------------------------------------------- /* Font */ //tmfont2.printString("GWOS:", 210, 45); /* Render Cockpit */ mod2.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 */ uniform2.DeleteShader(n_shaderProgram); } //--------------------------------------------------------------------------