void EJCanvasContext::prepare() { //Bind the frameBuffer and vertexBuffer array #ifdef _WINDOWS glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, msaaEnabled ? msaaFrameBuffer : viewFrameBuffer ); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, msaaEnabled ? msaaRenderBuffer : viewRenderBuffer ); #else glBindFramebufferOES(GL_FRAMEBUFFER_OES, msaaEnabled ? msaaFrameBuffer : viewFrameBuffer ); glBindRenderbufferOES(GL_RENDERBUFFER_OES, msaaEnabled ? msaaRenderBuffer : viewRenderBuffer ); #endif glViewport(0, 0, viewportWidth, viewportHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); #ifdef _WINDOWS glOrtho(0, width, 0, height, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); #else glOrthof(0, width, 0, height, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); #endif EJCompositeOperation op = state->globalCompositeOperation; glBlendFunc( EJCompositeOperationFuncs[op].source, EJCompositeOperationFuncs[op].destination ); glDisable(GL_TEXTURE_2D); currentTexture = NULL; EJTexture::setSmoothScaling(imageSmoothingEnabled); bindVertexBuffer(); if( state->clipPath ) { glDepthFunc(GL_EQUAL); } else { glDepthFunc(GL_ALWAYS); } }
int main( void ) { initGLFW(); initWindow(); initGLEW(); initKeyboard(); // Dark blue background glClearColor(0.0f, 0.0f, 0.4f, 0.0f); int size = 5; float* map = generateHeightMap(size); printf("generated map\n" ); std::vector<glm::vec3> terrain; mapHeightsToPoints(terrain, map, size); printf("mapped to points\n"); // GLuint* indices = generateIndices(terrain, size); uint terrainVertexAmount = size* size * 3; uint indiceAmount = 3 * (1 << size); for(int i = 0; i < terrain.size(); ++i){ printf("[%f, %f, %f]\n", terrain[i].x, terrain[i].y, terrain[i].z); } printf("vertices %d\n", terrainVertexAmount); GLuint VertexArrayID = newVertexArray(); // Create and compile our GLSL program from the shaders GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" ); printf("loaded\n"); initMatrices(programID); GLuint vertexbuffer = newVertexBuffer(terrainVertexAmount, &terrain); double lastTime = glfwGetTime(); int nbFrames = 0; printf("loop\n"); initDepth(); do{ // Clear the screen glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Use our shader glUseProgram(programID); // TODO // recalculateMatrices(); // Send our transformation to the currently bound shader, // in the "MVP" uniform glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); // 1rst attribute buffer : vertices bindVertexBuffer(vertexbuffer); // Draw the triangle ! glDrawArrays(GL_TRIANGLE_FAN, 0, terrainVertexAmount); // 3 indices starting at 0 -> 1 triangle glDisableVertexAttribArray(0); // Swap buffers glfwSwapBuffers(window); glfwPollEvents(); // measureTime(lastTime, &nbFrames); } // Check if the ESC key was pressed or the window was closed while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0 ); // Cleanup VBO glDeleteBuffers(1, &vertexbuffer); glDeleteVertexArrays(1, &VertexArrayID); glDeleteProgram(programID); // Close OpenGL window and terminate GLFW glfwTerminate(); // normal** ns = generateNormals(map, size); return 0; }