/********************************************************************* * * * FLY * * --E#Y#E-- * * ===MUSCLE=== * * * *********************************************************************/ /* Header Files */ #include "opengl.h" /*-------------------------------------------------------------------------*/ 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 */ char code03; float code1; float code2; float angle3; /* Cube Map */ int PIX; GLuint texID[ID]; GLuint m_cubeMapTexID; /*---------------------------------------------------------------------------*/ /* Bool */ char Fday = FALSE; char Fnight = FALSE; char Fblack = TRUE; char Fgrid = TRUE; char Ftexture = FALSE; char Fcloud = FALSE; char Fpurple = FALSE; /*-------------------------------------------------------------------------*/ /* Vector */ GLfloat vcolor3[AV]; GLfloat tcircle3[AV]; GLfloat vcircle3[AV]; /* Buffer */ GLfloat m_colors[AV]; GLfloat m_texCoords[AV]; GLfloat m_vertices[AV]; /* Index */ GLuint m_indices[AV]; /*-------------------------------------------------------------------------*/ /* 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 loadTexture() { #if PNG_TEXTURE /* Load PNG Texture */ const char *forestPNG; const char *desertPNG; const char *seaocePNG; const char *cloudPNG; /* PNG Textures */ forestPNG = "PIXEL/forest.png"; desertPNG = "PIXEL/desert.png"; seaocePNG = "PIXEL/sea.png"; cloudPNG = "PIXEL/cloud.png"; /* Read PNG */ read_png(forestPNG, &bla); read_png(desertPNG, &des); read_png(seaocePNG, &sea); read_png(cloudPNG, &sky); /* Load Textures */ printf(" LOADING TEXTURES 2: \n"); #endif } /*---------------------------------------------------------------------------*/ /* GLEW Init */ void 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) { printf(" OPENGL SUPPORTED: \n"); } /* Shader Version */ char *shaderversion = (char *)glGetString(GL_SHADING_LANGUAGE_VERSION); if(GL_SHADING_LANGUAGE_VERSION) { printf(" SHADER VERSION: %s \n", shaderversion); } /* OpenGL Version */ char *version = (char *)glGetString(GL_VERSION); if(GL_VERSION) { printf(" OPENGL VERSION: %s \n", version); } } /*---------------------------------------------------------------------------*/ /* Shader Language */ char 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 */ createShader(fly_vert, fly_frag); createProgram(m_shaderProgram); /* Init */ Location(m_shaderProgram, 0, "a_Vertex"); Location(m_shaderProgram, 1, "a_TexCoord"); Location(m_shaderProgram, 2, "a_Color"); /* Re link the program */ /*linkProgram(m_shaderProgram);*/ /*bindShader(m_shaderProgram);*/ /*-----------------------------------------------------------------*/ /* Create GLSL Shaders / Compile Shaders */ createShader(cube_vert, cube_frag); createProgram(m_cubeProgram); /* Init */ Location(m_cubeProgram, 0, "c_Vertex"); Location(m_cubeProgram, 1, "c_TexCoord"); Location(m_cubeProgram, 2, "c_Normal"); /* Re link the program */ linkProgram(m_cubeProgram); /*bindShader(m_cubeProgram);*/ /*-----------------------------------------------------------------*/ /* Create GLSL Shaders / Compile Shaders */ createShader(basic_vert, basic_frag); createProgram(m_basicProgram); /* Init */ Location(m_basicProgram, 0, "b_Vertex"); Location(m_basicProgram, 1, "b_TexCoord"); /* Re link the program */ linkProgram(m_basicProgram); 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 */ Uniform4x4(m_shaderProgram, "projection_matrix", 0, projection3); Uniform4x4(m_shaderProgram, "modelview_matrix", 1, modelview3); return TRUE; } /*---------------------------------------------------------------------------*/ /* Init Grid */ char initGrid() { 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"); } /*-----------------------------------------------------------------*/ /* 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 Box */ if(!initBox()) { printf(" COULD NOT INITIALIZE THE BOX \n"); return FALSE; } /* Initialize the View */ if(!initCockpit()) { printf(" COULD NOT INITIALIZE THE VIEW \n"); return FALSE; } /* Initialize the Shader */ if(!textureShader3()) { printf(" COULD NOT INITIALIZE THE SHADER \n"); return FALSE; } #endif /*------------------------------------------------------------------*/ #if LAND_VECTOR /* Texture */ GridRender(forestFile); GridRender(desertFile); GridRender(seaoceFile); GridRender(cloudFile); /* Grid */ GridRender(gridFileO); GridRender(gridFileT); GridRender(gridFileL); 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 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 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 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 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 */ F_Color(gl.col.r, gl.col.g, gl.col.b, gl.col.a); F_Textur(gl.tex.s, gl.tex.t); F_Vertex(gl.tri.x, gl.tri.y, gl.tri.z); /* ELEMENTS */ m_indices[w++]; m_indices[w++]; m_indices[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 PolygonCircle(const GLenum mode, const GLenum front, const char *nFile) { glPolygonMode(GL_FRONT_AND_BACK, front); glBegin(mode); GridRender(nFile); glEnd(); } /*---------------------------------------------------------------------------*/ /* Draw Arrays */ void 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 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 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_BYTE, /* type */ pixel /* data */ ); glTexSubImage2D(GL_TEXTURE_2D,0,0,0,128,128,GL_BGRA,GL_UNSIGNED_BYTE,pixel); glTexSubImage2D(GL_TEXTURE_2D,0,2,0,128,128,GL_BGRA,GL_UNSIGNED_BYTE,pixel); glTexSubImage2D(GL_TEXTURE_2D,0,0,2,128,128,GL_BGRA,GL_UNSIGNED_BYTE,pixel); glTexSubImage2D(GL_TEXTURE_2D,0,2,2,128,128,GL_BGRA,GL_UNSIGNED_BYTE,pixel); #if LAND_VECTOR DrawCircle(GL_TRIANGLES, GL_FILL, count, 0); #else PolygonCircle(GL_TRIANGLES, GL_FILL, nFile); #endif /* Disable Texture */ glDisable(GL_TEXTURE_2D); glFlush(); } /*---------------------------------------------------------------------------*/ /* Point Speed */ void 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 pointGrid(float dt) { /* Cloud */ float speedC = 0.2f; float maxCloud = +90.0f; float minCloud = -90.0f; /* Speed */ pointSpeed(dt, speedC, maxCloud, minCloud); } /*---------------------------------------------------------------------------*/ /* Moving Objects */ void Objects(int PIX) { /* Primitives */ 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 */ DrawCircle(modeP, frontP, countP, offsetP); DrawCircle(modeT, frontL, countL, offsetL); DrawCircle(modeT, frontF, countT, offsetT); /*glRotatef(-code1, 0.0f, 1.0f, 0.0f);*/ /*glRotatef(-code2, 0.0f, 1.0f, 0.0f);*/ DrawCircle(modeL, frontL, countE, offsetE); #else /* Polygon Circle */ PolygonCircle(modeP, frontP, gridFileO); PolygonCircle(modeT, frontL, gridFileT); PolygonCircle(modeT, frontF, gridFileL); /*glRotatef(-code1, 0.0f, 1.0f, 0.0f);*/ /*glRotatef(-code2, 0.0f, 1.0f, 0.0f);*/ PolygonCircle(modeL, frontL, gridFileU); #endif /* Disable Anti-aliasing */ glDisable(GL_LINE_SMOOTH); glDisable(GL_POINT_SMOOTH); glDisable(GL_POLYGON_SMOOTH); glFlush(); } /*------------------------------------------------------------------*/ /* Basic Program */ /*linkProgram(m_basicProgram);*/ /*bindShader(m_basicProgram);*/ /*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 */ SubImage(countF, forestFile, bla); SubImage(countD, desertFile, des); 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 */ SubImage(countC, cloudFile, sky); } /* Delete Textures */ glDeleteTextures(PIX, texID); glFlush(); } /*---------------------------------------------------------------------------*/ /* Render Objects */ void 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, &vcolor3[coffset]);*/ /*-----------------------------------------------------------------*/ 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, &vcircle3[voffset]);*/ /*-----------------------------------------------------------------*/ 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, &tcircle3[toffset]);*/ /*-----------------------------------------------------------------*/ /* Objects */ 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 */ /*glActiveTextureARB(GL_TEXTURE0_ARB);*/ /*glClientActiveTextureARB(GL_TEXTURE0_ARB);*/ } /*---------------------------------------------------------------------------*/ /* Render Landscape */ void 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 */ CameraLook(); 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 */ initBox(); 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 */ bindShader(m_cubeProgram); sendUniform3f(m_cubeProgram, "camera_position", 0.0f, 0.0f, 0.0f); 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 */ renderObjects(PIX); /*------------------------------------------------------------------*/ /* Shader Program */ linkProgram(m_shaderProgram); /* Re link the program */ bindShader(m_shaderProgram); /* Enable our shader */ Uniform(m_shaderProgram, "texture0", 0); /* Disable the stencil test */ glDisable(GL_STENCIL_TEST); //************************************************************* // Draw the sphere normal //************************************************************* /* Render Objects */ renderObjects(PIX); CubeMap(); /*------------------------------------------------------------------*/ /* Delete Buffer */ glDeleteBuffers(MAX_BUFFERS, &vbos3[0]); /* Delete Shader */ DeleteShader(m_shaderProgram); DeleteShader(m_cubeProgram); DeleteShader(m_basicProgram); /* Disable */ glDisable(GL_COLOR_MATERIAL); glDisable(GL_LIGHTING); glDisable(GL_AMBIENT); /*glDisable(GL_CULL_FACE);*/ } /*-------------------------------------------------------------------------*/ /* Render Landscape */ void CubeMap() { #if CUBE_MAP int TEX = 0; glClear(GL_DEPTH_BUFFER_BIT); glLoadIdentity(); beginCubeMapRendering(256); /* Number of Texture */ for(TEX = 0; TEX < 6; ++TEX) { /* Cube Render */ beginCubeMapFace(TEX); /* Flybox */ initBox(); render( 0, 0, 0, m_basicProgram); /* Translate Y-Achse */ glTranslatef(0.0f, 2.0f, 0.0f); /* Render Objects */ renderObjects(PIX); finishCubeMapFace(TEX, 256); } /* 2.0 Window */ endCubeMapRendering(); #endif } /*-------------------------------------------------------------------------*/ /* Process Event */ void 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: closeWin(); break; } } /*---------------------------------------------------------------------------*/