/********************************************************************* * * * FLY * * --E#Y#E-- * * ===MUSCLE=== * * * *********************************************************************/ /* Header Files */ #include "opengl.h" /* Class */ UNIFORM uniform3; FLYBOX flybox3; CUBE cube3; TMFONT tmfont3; TARGA targa3; PNG png3; MOV mov3; MOD mod3; FLY fly3; WIND wind3; //-------------------------------------------------------------------------- PFNGLGENBUFFERSARBPROC glGenBuffers = NULL; PFNGLBINDBUFFERPROC glBindBuffer = NULL; PFNGLBUFFERDATAPROC glBufferData = NULL; /* Buffer */ GLuint vbos3[MAX_BUFFERS]; //--------------------------------------------------------------------------- /* Init Color */ struct f_color { float r; float g; float b; float a; }f1, m1; /* Textures Coordinate */ struct f_texture { float s; float t; float p; float q; }f2, m2; /* Init Triangles */ struct f_triangles { float x; float y; float z; float w; }f3, m3; /* Structure Float */ struct f_float { struct f_color col; struct f_texture tex; struct f_triangles tri; }gl; //--------------------------------------------------------------------------- /* Motor */ bool code03; float code1; float code2; float angle3; /* Cube Map */ int PIX; GLuint texID[ID]; GLuint m_cubeMapTexID; //--------------------------------------------------------------------------- /* Bool */ bool Fday = false; bool Fnight = false; bool Fblack = true; bool Fgrid = true; bool Ftexture = false; bool Fcloud = false; bool Fpurple = false; //-------------------------------------------------------------------------- /* Vector */ vector vcolor3; vector tcircle3; vector vcircle3; /* Buffer */ vector m_colors; vector m_texCoords; vector m_vertices; /* Index */ vector m_indices; //-------------------------------------------------------------------------- /* Shader Program */ unsigned int m_shaderProgram; unsigned int m_basicProgram; unsigned int m_cubeProgram; //--------------------------------------------------------------------------- /* Grid */ const char gridFileO[] = "DATA/gridO.fs"; const char gridFileT[] = "DATA/gridT.fs"; const char gridFileL[] = "DATA/gridL.fs"; const char gridFileU[] = "DATA/gridU.fs"; /* Texture */ const char forestFile[] = "DATA/forest.fs"; const char desertFile[] = "DATA/desert.fs"; const char seaoceFile[] = "DATA/seaoce.fs"; const char cloudFile[] = "DATA/cloud.fs"; //--------------------------------------------------------------------------- /* Texture */ GLubyte *bla; GLubyte *des; GLubyte *sea; GLubyte *sky; //--------------------------------------------------------------------------- /* Load Texture */ void FLY::loadTexture() { #if PNG_TEXTURE /* Textures PNG */ const char forestPNG[] = "PIXEL/forest.png"; const char desertPNG[] = "PIXEL/desert.png"; const char seaocePNG[] = "PIXEL/sea.png"; const char cloudPNG[] = "PIXEL/cloud.png"; /* Read PNG */ png3.read_png(forestPNG, &bla); png3.read_png(desertPNG, &des); png3.read_png(seaocePNG, &sea); png3.read_png(cloudPNG, &sky); #endif #if TARGA_TEXTURE /* Textures TGA */ const char forestTGA[] = "PIXEL/forest.tga"; const char desertTGA[] = "PIXEL/desert.tga"; const char seaoceTGA[] = "PIXEL/sea.tga"; const char cloudTGA[] = "PIXEL/cloud.tga"; /* Load TGA */ targa3.readTarga(forestTGA, &bla); targa3.readTarga(desertTGA, &des); targa3.readTarga(seaoceTGA, &sea); targa3.readTarga(cloudTGA, &sky); #endif /* Load Textures */ std::cerr << " LOADING TEXTURES 2: " << std::endl; } //--------------------------------------------------------------------------- /* GLEW Init */ void FLY::glewStatus() { /* GLEW Init */ GLenum err = glewInit(); if(GLEW_OK != err) { fprintf(stderr," GLEW ERROR: %s \n", glewGetErrorString(err)); } /* GLEW Version */ fprintf(stdout," GLEW VERSION: %s \n", glewGetString(GLEW_VERSION)); /* Version 130 */ if(GLEW_VERSION_1_3) { std::cerr << " OPENGL SUPPORTED: " << std::endl; } /* Shader Version */ char *shaderversion = (char *)glGetString(GL_SHADING_LANGUAGE_VERSION); if(GL_SHADING_LANGUAGE_VERSION) { std::cout << " SHADER VERSION: " << shaderversion << std::endl; } /* OpenGL Version */ char *version = (char *)glGetString(GL_VERSION); if(GL_VERSION) { std::cout << " OPENGL VERSION: " << version << std::endl; } } //--------------------------------------------------------------------------- /* Shader Language */ bool FLY::textureShader3() { /* Fly Version */ static const GLchar fly_vert[] = "GLSL/fly.vert"; static const GLchar fly_frag[] = "GLSL/fly.frag"; /* Cube Version */ static const GLchar cube_vert[] = "GLSL/cube.vert"; static const GLchar cube_frag[] = "GLSL/cube.frag"; /* Basic Version */ static const GLchar basic_vert[] = "GLSL/basic.vert"; static const GLchar basic_frag[] = "GLSL/basic.frag"; //------------------------------------------------------------------- /* Create GLSL Shaders / Compile Shaders */ uniform3.createShader(fly_vert, fly_frag); uniform3.createProgram(m_shaderProgram); /* Init */ uniform3.Location(m_shaderProgram, 0, "a_Vertex"); uniform3.Location(m_shaderProgram, 1, "a_TexCoord"); uniform3.Location(m_shaderProgram, 2, "a_Color"); /* Re link the program */ //uniform3.linkProgram(m_shaderProgram); //uniform3.bindShader(m_shaderProgram); //------------------------------------------------------------------- /* Create GLSL Shaders / Compile Shaders */ uniform3.createShader(cube_vert, cube_frag); uniform3.createProgram(m_cubeProgram); /* Init */ uniform3.Location(m_cubeProgram, 0, "c_Vertex"); uniform3.Location(m_cubeProgram, 1, "c_TexCoord"); uniform3.Location(m_cubeProgram, 2, "c_Normal"); /* Re link the program */ uniform3.linkProgram(m_cubeProgram); //uniform3.bindShader(m_cubeProgram); //------------------------------------------------------------------- /* Create GLSL Shaders / Compile Shaders */ uniform3.createShader(basic_vert, basic_frag); uniform3.createProgram(m_basicProgram); /* Init */ uniform3.Location(m_basicProgram, 0, "b_Vertex"); uniform3.Location(m_basicProgram, 1, "b_TexCoord"); /* Re link the program */ uniform3.linkProgram(m_basicProgram); uniform3.bindShader(m_basicProgram); //------------------------------------------------------------------- /* Matrix */ static float modelview3[ID]; static float projection3[ID]; /* Passing Data */ glGetFloatv(GL_PROJECTION_MATRIX, projection3); glGetFloatv(GL_MODELVIEW_MATRIX, modelview3); /* Matrix */ uniform3.Uniform4x4(m_shaderProgram, "projection_matrix", 0, projection3); uniform3.Uniform4x4(m_shaderProgram, "modelview_matrix", 1, modelview3); return true; } //--------------------------------------------------------------------------- /* Init Landscape */ bool FLY::initGrid() { 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; } //------------------------------------------------------------------- /* Background Color */ glEnable(GL_BLEND); glEnable(GL_AMBIENT); glEnable(GL_LIGHT7); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); glEnable(GL_SCISSOR_TEST); glEnable(GL_COLOR_MATERIAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //------------------------------------------------------------------- /* Night */ if(Fnight) { glClearColor( 0.10f , 0.20f , 0.30f , 0.5f ); glDisable(GL_LIGHT7); } /* Day */ else if(Fday) { glClearColor( 0.30f , 0.50f , 0.70f , 0.5f ); glDisable(GL_LIGHTING); } /* Grid */ else if(Fblack) { glClearColor( 0.01f , 0.01f , 0.01f , 0.5f ); glDisable(GL_LIGHTING); } //------------------------------------------------------------------- /* Clear everything */ glClearDepth(1.0); /* Enable */ glEnable(GL_BLEND); //glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); //glDepthFunc(GL_LEQUAL); //------------------------------------------------------------------- #if SLOW_COMPUTER /* Initialize the Font */ if(!tmfont3.initFont()) { std::cerr << " COULD NOT INITIALIZE THE FONT " << std::endl; return false; } /* Initialize the Box */ if(!flybox3.initBox()) { std::cerr << " COULD NOT INITIALIZE THE BOX " << std::endl; return false; } /* Initialize the View */ if(!mod3.initCockpit()) { std::cerr << " COULD NOT INITIALIZE THE VIEW " << std::endl; return false; } /* Initialize the Shader */ if(!fly3.textureShader3()) { std::cerr << " COULD NOT INITIALIZE THE SHADER " << std::endl; return false; } #endif //------------------------------------------------------------------- #if LAND_VECTOR /* Texture */ fly3.GridRender(forestFile); fly3.GridRender(desertFile); fly3.GridRender(seaoceFile); fly3.GridRender(cloudFile); /* Grid */ fly3.GridRender(gridFileO); fly3.GridRender(gridFileT); fly3.GridRender(gridFileL); fly3.GridRender(gridFileU); #endif //------------------------------------------------------------------- /* Create Color Buffer */ glGenBuffers(MAX_BUFFERS, &vbos3[0]); glBindBuffer(GL_ARRAY_BUFFER, vbos3[COLOR_BUFFER]); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 4 * AV, &m_colors[0], GL_STATIC_DRAW); /* Create Texture Buffer */ glBindBuffer(GL_ARRAY_BUFFER, vbos3[NORMAL_BUFFER]); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 2 * AV, &m_texCoords[0], GL_STATIC_DRAW); /* Create Vertex Buffer */ glBindBuffer(GL_ARRAY_BUFFER, vbos3[VERTEX_BUFFER]); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * AV, &m_vertices[0], GL_STATIC_DRAW); //------------------------------------------------------------------- /* Create Element Buffer */ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos3[INDEX_BUFFER]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * 3 * AV, &m_indices[0], GL_STATIC_DRAW); return true; } //--------------------------------------------------------------------------- /* X / Y / Z / W */ float FLY::F_Vertex(float fx, float fy, float fz) { float vcircle3[3]; vcircle3[0] = 0; vcircle3[1] = 0; vcircle3[2] = 0; vcircle3[0] = fx; vcircle3[1] = fy; vcircle3[2] = fz; return *vcircle3; } //--------------------------------------------------------------------------- /* R / G / B / A */ float FLY::F_Color(float fr, float fg, float fb, float fa) { float vcolor3[4]; vcolor3[0] = 0; vcolor3[1] = 0; vcolor3[2] = 0; vcolor3[3] = 0; vcolor3[0] = fr; vcolor3[1] = fg; vcolor3[2] = fb; vcolor3[3] = fa; return *vcolor3; } //--------------------------------------------------------------------------- /* S / T / P / Q */ float FLY::F_Textur(float fs, float ft) { float tcircle3[2]; tcircle3[0] = 0; tcircle3[1] = 0; tcircle3[0] = fs; tcircle3[1] = ft; return *tcircle3; } //--------------------------------------------------------------------------- /* Render Grid */ void FLY::GridRender(const char *nFile) { /* Load File */ char code; int w = 0; FILE *grid; grid=fopen(nFile,"r"); /* Grid File */ while(fscanf(grid,"%s %f %f %f %f %f %f %f %f %f", &code, &gl.col.r, &gl.col.g, &gl.col.b, &gl.col.a, &gl.tex.s, &gl.tex.t, &gl.tri.x, &gl.tri.y, &gl.tri.z) != EOF) { #if LAND_VECTOR /* VERTEX */ m_colors.push_back(M_Color(gl.col.r, gl.col.g, gl.col.b, gl.col.a)); m_texCoords.push_back(M_Textur(gl.tex.s, gl.tex.t)); m_vertices.push_back(M_Vertex(gl.tri.x, gl.tri.y, gl.tri.z)); /* ELEMENTS */ m_indices.push_back(w++); m_indices.push_back(w++); m_indices.push_back(w++); #else /* ARRAY */ glColor4f(gl.col.r, gl.col.g, gl.col.b, gl.col.a); glTexCoord2f(gl.tex.s, gl.tex.t); glVertex3f(gl.tri.x, gl.tri.y, gl.tri.z); #endif } /* Close File */ fclose(grid); } //-------------------------------------------------------------------------- /* Polygon Mode */ void FLY::PolygonCircle(const GLenum mode, const GLenum front, const char *nFile) { glPolygonMode(GL_FRONT_AND_BACK, front); glBegin(mode); fly3.GridRender(nFile); glEnd(); } //-------------------------------------------------------------------------- /* Draw Arrays */ void FLY::DrawCircle(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(); } //--------------------------------------------------------------------------- /* Mipmaps Image */ void FLY::MipmapsImage(const GLint count, int side3, GLubyte *pixel) { /* Generate Textures */ glGenTextures(side3, texID); //glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texID[side3]); /* Enable Texture */ glEnable(GL_TEXTURE_2D); /* Generate MipMaps */ glGenerateMipmap(GL_TEXTURE_2D); /* Filtering Mode */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); /* Image Data */ //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 512, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixel); //glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 256, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixel); //glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 128, 128, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixel); //glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 64, 64, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixel); //glTexImage2D(GL_TEXTURE_2D, 4, GL_RGBA8, 32, 32, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixel); //glTexImage2D(GL_TEXTURE_2D, 5, GL_RGBA8, 16, 16, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixel); //glTexImage2D(GL_TEXTURE_2D, 6, GL_RGBA8, 8, 8, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixel); //glTexImage2D(GL_TEXTURE_2D, 7, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixel); //glTexImage2D(GL_TEXTURE_2D, 8, GL_RGBA8, 2, 2, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixel); //glTexImage2D(GL_TEXTURE_2D, 9, GL_RGBA8, 1, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixel); /* Mipmaps Data */ //gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA8, 512, 512, GL_BGRA, GL_UNSIGNED_BYTE, pixel); /* Cube Map */ glGenTextures(1, &m_cubeMapTexID); glBindTexture(GL_TEXTURE_CUBE_MAP, m_cubeMapTexID); /* Filtering Mode */ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); /* Disable Texture */ glDisable(GL_TEXTURE_2D); /* Delete Texture */ glDeleteTextures(side3, texID); glFlush(); } //--------------------------------------------------------------------------- /* Render Landscape */ void FLY::SubImage(const GLint count, const char *nFile, GLubyte *pixel) { /* Enable Texture */ glEnable(GL_TEXTURE_2D); /* Filtering Mode */ //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); /* Image Data */ glTexImage2D(GL_TEXTURE_2D, 0, // level GL_RGBA8, // internal format 128, // width 128, // height 0, // border GL_BGRA, // format GL_UNSIGNED_SHORT, // type pixel // data ); glTexSubImage2D(GL_TEXTURE_2D,0,0,0,128,128,GL_BGRA,GL_UNSIGNED_SHORT,pixel); glTexSubImage2D(GL_TEXTURE_2D,0,2,0,128,128,GL_BGRA,GL_UNSIGNED_SHORT,pixel); glTexSubImage2D(GL_TEXTURE_2D,0,0,2,128,128,GL_BGRA,GL_UNSIGNED_SHORT,pixel); glTexSubImage2D(GL_TEXTURE_2D,0,2,2,128,128,GL_BGRA,GL_UNSIGNED_SHORT,pixel); #if LAND_VECTOR fly3.DrawCircle(GL_TRIANGLES, GL_FILL, count, 0); #else fly3.PolygonCircle(GL_TRIANGLES, GL_FILL, nFile); #endif /* Disable Texture */ glDisable(GL_TEXTURE_2D); glFlush(); } //-------------------------------------------------------------------------- /* Point Speed */ void FLY::pointSpeed(float dt, float speed, float maxSpeed, float minSpeed) { /* Angle */ angle3 += 25.0f * dt; if(angle3 > 360.0f) { angle3 -= 360.0f; } /* Line */ if(code03) { code1 += speed; code2 -= speed; } else { code1 -= speed; code2 += speed; } /* Limit */ if(code1 >= maxSpeed) { code03 = false; } else if(code1 <= minSpeed) { code03 = true; } } //-------------------------------------------------------------------------- /* Point Grid */ void FLY::pointGrid(float dt) { /* Cloud */ float speedC = 0.2f; float maxCloud = +90.0f; float minCloud = -90.0f; /* Speed */ fly3.pointSpeed(dt, speedC, maxCloud, minCloud); } //-------------------------------------------------------------------------- /* Moving Objects */ void FLY::Objects(int PIX) { /* 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; //------------------------------------------------------------------- /* Grid */ if(Fgrid) { /* Enable Anti-aliasing */ glEnable(GL_POLYGON_SMOOTH); glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); /* Size */ glLineWidth(3.0); glPointSize(7.0); #if LAND_VECTOR /* Offset */ const GLint offsetP = 900; // 900 const GLint offsetL = 1800; // 1800 const GLint offsetT = 0; // 0 const GLint offsetE = 0; // 0 /* Count */ const GLint countP = 864; // 900 const GLint countL = 864; // 900 const GLint countT = 864; // 900 const GLint countE = 864; // 900 /* Draw Circle */ fly3.DrawCircle(modeP, frontP, countP, offsetP); fly3.DrawCircle(modeT, frontL, countL, offsetL); fly3.DrawCircle(modeT, frontF, countT, offsetT); //glRotatef(-code1, 0.0f, 1.0f, 0.0f); //glRotatef(-code2, 0.0f, 1.0f, 0.0f); //fly3.DrawCircle(modeL, frontL, countE, offsetE); #else /* Polygon Circle */ fly3.PolygonCircle(modeP, frontP, gridFileO); fly3.PolygonCircle(modeT, frontL, gridFileT); fly3.PolygonCircle(modeT, frontF, gridFileL); //glRotatef(-code1, 0.0f, 1.0f, 0.0f); //glRotatef(-code2, 0.0f, 1.0f, 0.0f); //fly3.PolygonCircle(modeL, frontL, gridFileU); #endif /* Disable Anti-aliasing */ glDisable(GL_LINE_SMOOTH); glDisable(GL_POINT_SMOOTH); glDisable(GL_POLYGON_SMOOTH); glFlush(); } //------------------------------------------------------------------ /* Basic Program */ //uniform3.linkProgram(m_basicProgram); //uniform3.bindShader(m_basicProgram); //uniform3.Uniform(m_basicProgram, "texture1", 0); /* Generate Textures */ glGenTextures(PIX, texID); glBindTexture(GL_TEXTURE_2D_ARRAY, texID[PIX]); /* Landscape */ if(Ftexture) { /* Count */ const GLint countF = 288; // 290 const GLint countD = 672; // 670 const GLint countS = 864; // 900 /* SubImage */ fly3.SubImage(countF, forestFile, bla); fly3.SubImage(countD, desertFile, des); fly3.SubImage(countS, seaoceFile, sea); } /* Cloud */ if(Fcloud) { /* Count */ const GLint countC = 900; // 100 /* Translate / Rotate */ //glTranslatef(0.0, 0.0, -code1); //glRotatef(-code1, 0.0f, 1.0f, 0.0f); //glRotatef(-code2, 0.0f, 0.0f, 0.0f); /* Cloud File */ fly3.SubImage(countC, cloudFile, sky); } /* Delete Textures */ glDeleteTextures(PIX, texID); glFlush(); } //-------------------------------------------------------------------------- /* Render Objects */ void FLY::renderObjects(int PIX) { /* Active Texture */ //glActiveTextureARB(GL_TEXTURE5_ARB + PIX); //glClientActiveTextureARB(GL_TEXTURE5_ARB); /* Attrib Array */ //glEnableVertexAttribArrayARB(0); //glEnableVertexAttribArrayARB(1); //glEnableVertexAttribArrayARB(2); /* Vertex Array */ glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); //------------------------------------------------------------------- glBindBuffer(GL_ARRAY_BUFFER, vbos3[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, &vcolor3[coffset]); //glVertexAttribPointerARB((GLuint)2, csize, ctype, cnormalize, cstride, 0); //------------------------------------------------------------------- glBindBuffer(GL_ARRAY_BUFFER, vbos3[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, &vcircle3[voffset]); //glVertexAttribPointerARB((GLuint)0, vsize, vtype, vnormalize, vstride, 0); //------------------------------------------------------------------- glBindBuffer(GL_ARRAY_BUFFER, vbos3[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, &tcircle3[toffset]); //glVertexAttribPointerARB((GLuint)1, tsize, ttype, tnormalize, tstride, 0); //------------------------------------------------------------------- /* Objects */ fly3.Objects(PIX); //------------------------------------------------------------------- /* Disable Client State */ glDisableClientState(GL_TEXTURE_COORD_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); } //-------------------------------------------------------------------------- /* Render Landscape */ void FLY::Landscape(int width, int height) { /* Texture */ glDisable(GL_SCISSOR_TEST); /* Render Triangles */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); /* PlaneView */ mov3.CameraLook(); mov3.PlaneView(); //************************************************************* // Draw the plane with stencil on //************************************************************* glEnable(GL_STENCIL_TEST); //Enable stenciling glDepthMask(GL_FALSE); //Disable depth writes /* Always replace the stencil value whether it passes or fails */ glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); /* Make the test always pass */ glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF); /* Flybox */ flybox3.initBox(); flybox3.render(0, 0, 0, m_basicProgram); /* Re-enable depth writes */ glDepthMask(GL_TRUE); //************************************************************* // Draw the sphere's reflection, with blending and stencil testing //************************************************************* /* Cube Program */ uniform3.bindShader(m_cubeProgram); uniform3.sendUniform3f(m_cubeProgram, "camera_position", 0.0f, 0.0f, 0.0f); uniform3.Uniform(m_cubeProgram, "texture2", 0); /* Cube Map */ glBindTexture(GL_TEXTURE_CUBE_MAP, m_cubeMapTexID); /* Only render where the stencil value is 1 */ glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF); /* Don’t change the stencil values any more */ glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); /* Purple Look */ if(Fpurple) { glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE); } /* Render Objects */ fly3.renderObjects(PIX); //------------------------------------------------------------------- /* Font */ //tmfont3.printString("VULKANO:", 110, 25); /* Shader Program */ uniform3.linkProgram(m_shaderProgram); // Re link the program uniform3.bindShader(m_shaderProgram); // Enable our shader uniform3.Uniform(m_shaderProgram, "texture0", 0); /* Disable the stencil test */ glDisable(GL_STENCIL_TEST); //************************************************************* // Draw the sphere normal //************************************************************* /* Render Objects */ fly3.renderObjects(PIX); fly3.CubeMap(); //------------------------------------------------------------------- /* Delete Buffer */ glDeleteBuffers(MAX_BUFFERS, &vbos3[0]); /* Delete Shader */ uniform3.DeleteShader(m_shaderProgram); uniform3.DeleteShader(m_cubeProgram); uniform3.DeleteShader(m_basicProgram); /* Disable */ glDisable(GL_COLOR_MATERIAL); glDisable(GL_LIGHTING); glDisable(GL_AMBIENT); //glDisable(GL_CULL_FACE); } //--------------------------------------------------------------------------- /* Render Landscape */ void FLY::CubeMap() { #if CUBE_MAP int TEX = 0; glClear(GL_DEPTH_BUFFER_BIT); glLoadIdentity(); cube3.beginCubeMapRendering(256); /* Number of Texture */ for(TEX = 0; TEX < 6; ++TEX) { /* Cube Render */ cube3.beginCubeMapFace(TEX); /* Flybox */ flybox3.initBox(); flybox3.render( 0, 0, 0, m_basicProgram); /* Translate Y-Achse */ glTranslatef(0.0f, 2.0f, 0.0f); /* Render Objects */ fly3.renderObjects(PIX); cube3.finishCubeMapFace(TEX, 256); } /* 2.0 Window */ cube3.endCubeMapRendering(); #endif } //--------------------------------------------------------------------------- /* Process Event */ void FLY::process_event1(XEvent report) { KeySym key; key = XLookupKeysym (&report.xkey, 0); /* Keyboard Control Keys */ switch(key) { case XK_F5: Fday = false; Fnight = false; Fblack = true; Fgrid = true; Ftexture = false; Fcloud = false; break; case XK_F6: Fday = true; Fnight = false; Fblack = false; Fgrid = false; Ftexture = true; Fcloud = false; break; case XK_F7: Fday = true; Fnight = false; Fblack = false; Fgrid = false; Ftexture = true; Fcloud = true; break; case XK_F8: Fday = false; Fnight = true; Fblack = false; Fgrid = false; Ftexture = true; Fcloud = false; break; case XK_F9: Fpurple = true; break; case XK_F10: Fpurple = false; break; case XK_Escape: wind3.closeWin(); break; } } //---------------------------------------------------------------------------