//Create the buffers and store the mesh data in them void LoadMesh(MeshBuffers *buffers, MeshData *data, Vertex *vertices, unsigned int verticesCount, unsigned int *indices, unsigned int indicesCount) { data->VerticesCount = verticesCount; data->IndicesCount = indicesCount; data->Vertices = vertices; data->Indices = indices; //Use only with newer GLSL versions #if GLSL_VERSION == MODERN_VERSION //Generate a handle to a vertex array object glGenVertexArrays(1, &buffers->VAO); #endif //Generate a handle to a vertex buffer object glGenBuffers(1, &buffers->VBO); //Generate a handle to a element buffer object glGenBuffers(1, &buffers->EBO); //Bind the vertex array object (it will begin storing what is happening below BindMesh(buffers); //Create a Vertex buffer InitVBO(buffers, data); //Create an Element buffer InitEBO(buffers, data); //Unbind everything UnbindMesh(); }
//============================== // OvrDebugLinesLocal::Init void OvrDebugLinesLocal::Init() { if ( Initialized ) { // JDC: multi-activity test DROID_ASSERT( !Initialized, "DebugLines" ); return; } // this is only freed by the OS when the program exits if ( LineProgram.vertexShader == 0 || LineProgram.fragmentShader == 0 ) { LineProgram = BuildProgram( DebugLineVertexSrc, DebugLineFragmentSrc ); } const int MAX_VERTS = MAX_DEBUG_LINES * 2; Vertices = new LineVertex_t[ MAX_VERTS ]; // the indices will never change once we've set them up, we just won't necessarily // use all of the index buffer to render. const int MAX_INDICES = MAX_DEBUG_LINES * 2; LineIndex_t * indices = new LineIndex_t[ MAX_INDICES ]; for ( int i = 0; i < MAX_INDICES; ++i ) { indices[i] = i; } InitVBO( DepthGeo, Vertices, MAX_VERTS, indices, MAX_INDICES ); InitVBO( NonDepthGeo, Vertices, MAX_VERTS, indices, MAX_INDICES ); glBindVertexArrayOES_( 0 ); delete [] indices; // never needs to change so we don't keep it around Initialized = true; }
bool C4LandscapeRenderGL::Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pTexs, C4GroupSet *pGraphics) { Clear(); // Safe info this->iWidth = iWidth; this->iHeight = iHeight; this->pTexs = pTexs; // Allocate landscape textures if (!InitLandscapeTexture()) { LogFatal("[!] Could not initialize landscape texture!"); return false; } // Build texture, er, texture if (!InitMaterialTexture(pTexs)) { LogFatal("[!] Could not initialize landscape textures for rendering!"); return false; } // Load sclaer if (!LoadScaler(pGraphics)) { LogFatal("[!] Could not load scaler!"); return false; } // Load shader if (!LoadShaders(pGraphics)) { LogFatal("[!] Could not initialize landscape shader!"); return false; } if (!InitVBO()) { LogFatal("[!] Could not initialize landscape VBO!"); return false; } return true; }
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(RENDER_WIDTH,RENDER_HEIGHT); glutCreateWindow("shader cube"); glutDisplayFunc(display_everything); // shadow //glutDisplayFunc(display); //glutDisplayFunc(displayBumpMapping ); glutMouseFunc(mymouse); glutMotionFunc(mymotion); glutKeyboardFunc(mykey); // initialize GLEW GLenum err = glewInit(); if ( err != GLEW_OK) printf(" Error initializing GLEW! \n"); else printf("Initializing GLEW succeeded!\n"); string fileLoc = "/home/arindam/Course/lab5/src/cubeXform"; //programObject = SetupGLSL("/home/arindam/Course/lab3/cse5542Lab3/cubeXform"); //create shaders - assume the shaders are cubeXform.vert and cubeXform.frag programObject = SetupGLSL("/home/arindam/workspace/cse5542lab5/cubeXform"); InitGeometry(); InitTexture(); generateShadowFBO(); glEnable(GL_DEPTH_TEST); glClearColor(0,0,0,1.0f); glEnable(GL_CULL_FACE); glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); cout <<"init geometry done "<<endl; InitVBO(); cout <<" init vbo "<<endl; cout <<" init texture "<<endl; glutMainLoop(); }
int main(int argc, char** argv) { InitGeometry(); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(500,500); glutCreateWindow("Lab3 Kevin Yen"); glutDisplayFunc(display); glutMouseFunc(mymouse); glutMotionFunc(mymotion); glutKeyboardFunc(mykey); printf("%s\n","please see readme.txt for control detail"); #ifdef __APPLE__ #else glewInit(); #endif InitVBO(); glutMainLoop(); }
void scene::InitExtensions() { if(scene::ExtensionSupported("GL_ARB_vertex_buffer_object")) { LogToFile("GL_ARB_vertex_buffer_object supported"); VBO_ENABLED = true; } else { LogToFile("GL_ARB_vertex_buffer_object not supported"); VBO_ENABLED = false; } // if(VBO_ENABLED) InitVBO(); }
int main(int argc, char** argv) { InitGeometry(); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(500,500); glutCreateWindow("Lab2"); glutDisplayFunc(display); glutMouseFunc(mymouse); glutMotionFunc(mymotion); glutKeyboardFunc(mykey); #ifdef __APPLE__ #else glewInit(); #endif InitVBO(); glutMainLoop(); }
int main(int argc, char** argv) { int rc; Shader s; // set the camera to an initial position cam.setCamera(Vector3f(0,-10,100), Vector3f(0,0,0), Vector3f(0,1,0)); glutInit(&argc, argv); // glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH|GLUT_3_2_CORE_PROFILE); glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(600,600); glutInitWindowPosition(10, 10); glutCreateWindow("skybox"); glutDisplayFunc(renderFun); glutIdleFunc(idleFun); // setCallbackFun(); // initialize GLEW // GLenum err = glewInit(); // if ( err != GLEW_OK) printf(" Error initializing GLEW! \n"); loadTextures(); skybox.init(); // skybox2.init(); Init_Geometry(); InitVBO(); rc = loadShaders(s); if (rc != 0) { printf("error after createing shaders rc = %d \n", rc); getchar(); } glutMainLoop(); }
void TerrainGenerator::RenderHeightMap() // This Renders The Height Map As Quads { glPushMatrix(); int X = 0, Y = 0; // Create Some Variables To Walk The Array With. int x, y, z; // Create Some Variables For Readability glScalef(scaleValue, scaleValue * HEIGHT_RATIO, scaleValue); glTranslatef(-512,-120,-512); if(!g_HeightMap.size()) return; // Make Sure Our Height Data Is Valid glCullFace(GL_BACK); glEnable(GL_CULL_FACE); fVector3d first; fVector3d second; fVector3d third; fVector3d a; fVector3d b; fVector3d n; double l; if(_vboInit) { for ( X = 0; X < (MAP_SIZE-STEP_SIZE); X += STEP_SIZE ) { for ( Y = 0; Y < (MAP_SIZE-STEP_SIZE); Y += STEP_SIZE ) { //calcNormals first.x = X; first.y = Height(X, Y ); first.z = Y; second.x = X; second.y = Height(X, Y + STEP_SIZE); second.z = Y + STEP_SIZE; third.x = X + STEP_SIZE; third.y = Height(X + STEP_SIZE, Y ); third.z = Y; a.x = second.x - first.x; a.y = second.y - first.y; a.z = second.z - first.z; b.x = third.x - first.x; b.y = third.y - first.y; b.z = third.z - first.z; n.x = (a.y * b.z) - (a.z * b.y); n.y = (a.z * b.x) - (a.x * b.z); n.z = (a.x * b.y) - (a.y * b.x); // Normalize (divide by root of dot product) l = sqrt(n.x * n.x + n.y * n.y + n.z * n.z); n.x /= l; n.y /= l; n.z /= l; // Get The (X, Y, Z) Value For The Bottom Left Vertex x = X; y = Height(X, Y ); z = Y; SetTex(1.0f, 1.0f); SetNormal(n.x,n.y,n.z); SetVertice(x,y,z); // Get The (X, Y, Z) Value For The Top Left Vertex x = X; y = Height(X, Y + STEP_SIZE ); z = Y + STEP_SIZE ; SetTex(0.0f, 1.0f); SetNormal(n.x,n.y,n.z); SetVertice(x,y,z); // Send This Vertex a VBO then To OpenGL To Be Rendered // Get The (X, Y, Z) Value For The Top Right Vertex x = X + STEP_SIZE; y = Height(X + STEP_SIZE, Y + STEP_SIZE ); z = Y + STEP_SIZE ; SetTex(0.0f, 0.0f); SetNormal(n.x,n.y,n.z); SetVertice(x,y,z); // Get The (X, Y, Z) Value For The Bottom Right Vertex x = X + STEP_SIZE; y = Height(X + STEP_SIZE, Y ); z = Y; SetTex(1.0f, 0.0f); SetNormal(n.x,n.y,n.z); SetVertice(x,y,z); } } InitVBO(); _vboInit = false; } CreateVBO(); // Render Polygon glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glPopMatrix(); }