/********************************************************************* * * * FLY * * --E#Y#E-- * * ===MUSCLE=== * * * *********************************************************************/ #include "flybox.h" /* Class */ UNIFORM uniform4; TARGA targa4; PNG png4; FLY fly4; //--------------------------------------------------------------------------- /* Buffer */ GLuint vbos4[MAX_BUFFERS]; //--------------------------------------------------------------------------- /* Vector */ vector colors4; vector texCoords4; vector vertices4; /* Buffer */ vector w_colors; vector w_texCoords; vector w_vertices; //--------------------------------------------------------------------------- /* Shader Program */ unsigned int s_basicProgram; //--------------------------------------------------------------------------- /* Texture */ GLubyte *nor; GLubyte *eas; GLubyte *sou; GLubyte *wes; GLubyte *top; GLubyte *bot; //--------------------------------------------------------------------------- /* Texture Loader */ void FLYBOX::textureLoader() { #if PNG_TEXTURE /* Textures PNG */ const char northPNG[] = "PIXEL/FLYBOX/bk.png"; const char eastPNG[] = "PIXEL/FLYBOX/rt.png"; const char southPNG[] = "PIXEL/FLYBOX/ft.png"; const char westPNG[] = "PIXEL/FLYBOX/lt.png"; const char topPNG[] = "PIXEL/FLYBOX/up.png"; const char bottomPNG[] = "PIXEL/FLYBOX/dn.png"; /* Load PNG */ png4.read_png(northPNG, &nor); png4.read_png(eastPNG, &eas); png4.read_png(southPNG, &sou); png4.read_png(westPNG, &wes); png4.read_png(topPNG, &top); png4.read_png(bottomPNG, &bot); #endif #if TARGA_TEXTURE /* Textures TGA */ const char northTGA[] = "PIXEL/FLYBOX/bk.tga"; const char eastTGA[] = "PIXEL/FLYBOX/rt.tga"; const char southTGA[] = "PIXEL/FLYBOX/ft.tga"; const char westTGA[] = "PIXEL/FLYBOX/lt.tga"; const char topTGA[] = "PIXEL/FLYBOX/up.tga"; const char bottomTGA[] = "PIXEL/FLYBOX/dn.tga"; /* Load TGA */ targa4.readTarga(northTGA, &nor); targa4.readTarga(eastTGA, &eas); targa4.readTarga(southTGA, &sou); targa4.readTarga(westTGA, &wes); targa4.readTarga(topTGA, &top); targa4.readTarga(bottomTGA, &bot); #endif /* Load Textures */ std::cerr << " LOADING TEXTURES 1: " << std::endl; } //--------------------------------------------------------------------------- /* Init Skybox */ bool FLYBOX::initBox() { 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 /* Texture File */ int side = 0; const GLint countH = 75; /* Generate Textures */ glGenTextures(SS_MAX_SIDES, w_texID); for(side = 0; side < SS_MAX_SIDES; ++side) { /* SubImage */ fly4.MipmapsImage(countH, side, nor); fly4.MipmapsImage(countH, side, eas); fly4.MipmapsImage(countH, side, sou); fly4.MipmapsImage(countH, side, wes); fly4.MipmapsImage(countH, side, top); fly4.MipmapsImage(countH, side, bot); } #endif //------------------------------------------------------------------- /* Texture Size */ float SIZE = 50.0f; /* Top */ w_colors.push_back(M_Color(0.01f, 0.01f, 0.01f, 0.5f)); w_colors.push_back(M_Color(0.01f, 0.01f, 0.01f, 0.5f)); w_colors.push_back(M_Color(0.01f, 0.01f, 0.01f, 0.5f)); w_colors.push_back(M_Color(0.01f, 0.01f, 0.01f, 0.5f)); w_vertices.push_back(M_Vertex(-SIZE, SIZE, -SIZE)); w_vertices.push_back(M_Vertex( SIZE, SIZE, -SIZE)); w_vertices.push_back(M_Vertex( SIZE, SIZE, SIZE)); w_vertices.push_back(M_Vertex(-SIZE, SIZE, SIZE)); w_texCoords.push_back(M_Textur(0.0f, 0.0f)); w_texCoords.push_back(M_Textur(1.0f, 0.0f)); w_texCoords.push_back(M_Textur(1.0f, 1.0f)); w_texCoords.push_back(M_Textur(0.0f, 1.0f)); /* Left */ w_colors.push_back(M_Color(0.10f, 0.20f, 0.30f, 0.5f)); w_colors.push_back(M_Color(0.10f, 0.20f, 0.30f, 0.5f)); w_colors.push_back(M_Color(0.10f, 0.20f, 0.30f, 0.5f)); w_colors.push_back(M_Color(0.10f, 0.20f, 0.30f, 0.5f)); w_vertices.push_back(M_Vertex(-SIZE,-SIZE,-SIZE)); w_vertices.push_back(M_Vertex(-SIZE, SIZE,-SIZE)); w_vertices.push_back(M_Vertex(-SIZE, SIZE, SIZE)); w_vertices.push_back(M_Vertex(-SIZE,-SIZE, SIZE)); w_texCoords.push_back(M_Textur(1.0f, 0.0f)); w_texCoords.push_back(M_Textur(1.0f, 1.0f)); w_texCoords.push_back(M_Textur(0.0f, 1.0f)); w_texCoords.push_back(M_Textur(0.0f, 0.0f)); /* Back */ w_colors.push_back(M_Color(0.30f, 0.50f, 0.70f, 0.5f)); w_colors.push_back(M_Color(0.30f, 0.50f, 0.70f, 0.5f)); w_colors.push_back(M_Color(0.30f, 0.50f, 0.70f, 0.5f)); w_colors.push_back(M_Color(0.30f, 0.50f, 0.70f, 0.5f)); w_vertices.push_back(M_Vertex(-SIZE,-SIZE,-SIZE)); w_vertices.push_back(M_Vertex( SIZE,-SIZE,-SIZE)); w_vertices.push_back(M_Vertex( SIZE, SIZE,-SIZE)); w_vertices.push_back(M_Vertex(-SIZE, SIZE,-SIZE)); w_texCoords.push_back(M_Textur(0.0f, 0.0f)); w_texCoords.push_back(M_Textur(1.0f, 0.0f)); w_texCoords.push_back(M_Textur(1.0f, 1.0f)); w_texCoords.push_back(M_Textur(0.0f, 1.0f)); /* Right */ w_colors.push_back(M_Color(0.10f, 0.20f, 0.30f, 0.5f)); w_colors.push_back(M_Color(0.10f, 0.20f, 0.30f, 0.5f)); w_colors.push_back(M_Color(0.10f, 0.20f, 0.30f, 0.5f)); w_colors.push_back(M_Color(0.10f, 0.20f, 0.30f, 0.5f)); w_vertices.push_back(M_Vertex( SIZE,-SIZE, SIZE)); w_vertices.push_back(M_Vertex( SIZE, SIZE, SIZE)); w_vertices.push_back(M_Vertex( SIZE, SIZE,-SIZE)); w_vertices.push_back(M_Vertex( SIZE,-SIZE,-SIZE)); w_texCoords.push_back(M_Textur(1.0f, 0.0f)); w_texCoords.push_back(M_Textur(1.0f, 1.0f)); w_texCoords.push_back(M_Textur(0.0f, 1.0f)); w_texCoords.push_back(M_Textur(0.0f, 0.0f)); /* Bottom */ w_colors.push_back(M_Color(0.01f, 0.01f, 0.01f, 0.5f)); w_colors.push_back(M_Color(0.01f, 0.01f, 0.01f, 0.5f)); w_colors.push_back(M_Color(0.01f, 0.01f, 0.01f, 0.5f)); w_colors.push_back(M_Color(0.01f, 0.01f, 0.01f, 0.5f)); w_vertices.push_back(M_Vertex( SIZE,-SIZE, -SIZE)); w_vertices.push_back(M_Vertex(-SIZE,-SIZE, -SIZE)); w_vertices.push_back(M_Vertex(-SIZE,-SIZE, SIZE)); w_vertices.push_back(M_Vertex( SIZE,-SIZE, SIZE)); w_texCoords.push_back(M_Textur(0.0f, 0.0f)); w_texCoords.push_back(M_Textur(1.0f, 0.0f)); w_texCoords.push_back(M_Textur(1.0f, 1.0f)); w_texCoords.push_back(M_Textur(0.0f, 1.0f)); /* Front */ w_colors.push_back(M_Color(0.30f, 0.50f, 0.70f, 0.5f)); w_colors.push_back(M_Color(0.30f, 0.50f, 0.70f, 0.5f)); w_colors.push_back(M_Color(0.30f, 0.50f, 0.70f, 0.5f)); w_colors.push_back(M_Color(0.30f, 0.50f, 0.70f, 0.5f)); w_vertices.push_back(M_Vertex( SIZE,-SIZE, SIZE)); w_vertices.push_back(M_Vertex(-SIZE,-SIZE, SIZE)); w_vertices.push_back(M_Vertex(-SIZE, SIZE, SIZE)); w_vertices.push_back(M_Vertex( SIZE, SIZE, SIZE)); w_texCoords.push_back(M_Textur(0.0f, 0.0f)); w_texCoords.push_back(M_Textur(1.0f, 0.0f)); w_texCoords.push_back(M_Textur(1.0f, 1.0f)); w_texCoords.push_back(M_Textur(0.0f, 1.0f)); //------------------------------------------------------------------- glGenBuffers(MAX_BUFFERS, &vbos4[0]); //Generate a buffer for the color glBindBuffer(GL_ARRAY_BUFFER, vbos4[COLOR_BUFFER]); //Bind the color buffer glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 4 * FB, &w_colors[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, vbos4[VERTEX_BUFFER]); //Bind the vertex buffer glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * FB, &w_vertices[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, vbos4[NORMAL_BUFFER]); //Bind the tex coord buffer glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 2 * FB, &w_texCoords[0], GL_STATIC_DRAW); return true; } //--------------------------------------------------------------------------- /* Render Skybox */ void FLYBOX::render(float x, float y, float z, unsigned int s_basicProgram) { glPushMatrix(); glTranslatef(x, y, z); //------------------------------------------------------------------- /* Matrix */ static float modelviewMatrix[ID]; static float projectionMatrix[ID]; glGetFloatv(GL_MODELVIEW_MATRIX, modelviewMatrix); glGetFloatv(GL_PROJECTION_MATRIX, projectionMatrix); uniform4.Uniform4x4(s_basicProgram, "modelview_matrix", 0, modelviewMatrix); uniform4.Uniform4x4(s_basicProgram, "projection_matrix", 1, projectionMatrix); //------------------------------------------------------------------- //glDisable(GL_DEPTH_TEST); //glEnable(GL_CULL_FACE); /* Vertex Array */ glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); /* Attrib Array */ //glEnableVertexAttribArrayARB(0); //glEnableVertexAttribArrayARB(1); //glEnableVertexAttribArrayARB(2); //------------------------------------------------------------------- glBindBuffer(GL_ARRAY_BUFFER, vbos4[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, &colors4[coffset]); //glVertexAttribPointerARB((GLuint)2, csize, ctype, cnormalize, cstride, &colors4[coffset]); //------------------------------------------------------------------- glBindBuffer(GL_ARRAY_BUFFER, vbos4[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, &vertices4[voffset]); //glVertexAttribPointerARB((GLuint)0, vsize, vtype, vnormalize, vstride, &vertices4[voffset]); //------------------------------------------------------------------- glBindBuffer(GL_ARRAY_BUFFER, vbos4[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, &texCoords4[toffset]); //glVertexAttribPointerARB((GLuint)1, tsize, ttype, tnormalize, tstride, &texCoords4[toffset]); //------------------------------------------------------------------- int i = 0; for(i = 0; i < 6; ++i) { glBindTexture(GL_TEXTURE_2D, w_texID[i]); glDrawArrays(GL_QUADS, i * 4, 4); } //------------------------------------------------------------------- /* Disable Array */ //glDisableVertexAttribArrayARB(2); //glDisableVertexAttribArrayARB(1); //glDisableVertexAttribArrayARB(0); /* Disable Client State */ glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); //glEnable(GL_DEPTH_TEST); glPopMatrix(); } //---------------------------------------------------------------------------