/* Draw a single frame */ void display(WorldState & state) { // Clear the color bits in the display buffer glClear(GL_COLOR_BUFFER_BIT); // Use a simple shader to render the line glUseProgram(shaderProg); checkGLError("useProgram"); //use the vertex array glBindVertexArray(vertexArray); //get uniform slot id //TODO: send a uniform value to the shader GLint timeSlot = glGetUniformLocation(shaderProg, "timeVal"); glUniform1f(timeSlot, state.getCurrentTime()); GLint mousexSlot = glGetUniformLocation(shaderProg, "mousexVal"); glUniform1i(mousexSlot, state.getMousePosx()); checkGLError("uniform"); // Render using vertex attributes (data already on GPU) (~2008, 3.0) // https://web.archive.org/web/20150225192608/http://www.arcsynthesis.org/gltut/Basics/Tut01%20Following%20the%20Data.html // Tell OpenGL we want to use a buffer on the GPU glBindBuffer(GL_ARRAY_BUFFER, positionBuffer); checkGLError("bind pos buffer"); // Tell OpenGL what shader data slot we want to use glEnableVertexAttribArray(positionSlot); checkGLError("enable pos slot"); // Tell OpenGL how to interpret the data glVertexAttribPointer(positionSlot, 2, GL_FLOAT, GL_FALSE, 0, 0); checkGLError("vertex attrib pos"); // Do the same thing for colors glBindBuffer(GL_ARRAY_BUFFER, colorBuffer); glEnableVertexAttribArray(colorSlot); glVertexAttribPointer(colorSlot, 3, GL_FLOAT, GL_FALSE, 0, 0); checkGLError("color array setup"); glBindBuffer(GL_ARRAY_BUFFER, sizeBuffer); checkGLError("bind size buffer"); glEnableVertexAttribArray(sizeSlot); checkGLError("enable size slot"); glVertexAttribPointer(sizeSlot, 1, GL_FLOAT, GL_FALSE, 0, 0); checkGLError("size array setup"); // Draw some primitives as: glDrawArrays(type, first, count) //TODO: replace these with your draw calls glDrawArrays(GL_TRIANGLES, 0, 12); glDrawArrays(GL_POINTS, 12, 1); //done with the vertex array glBindVertexArray(0); // Tell OpenGL we are done with the buffer glBindBuffer(GL_ARRAY_BUFFER, 0); // Tell OpenGL we are done with the shader glUseProgram(0); checkGLError("unbind"); }
void handleEvents(sf::Window & window, WorldState & state) { sf::Event event; while (window.pollEvent(event)) { // Close window : exit if (event.type == sf::Event::Closed) state.setRunning(false); // Escape key : exit if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)) state.setRunning(false); if (event.type == sf::Event::TextEntered) { Model const & model = state.getModel(); float time = state.getCurrentTime(); RenderEngine render = RenderEngine(render); switch (static_cast<char>(event.key.code)) { case 'q': printf("'q' should scale\n"); // scale = true. //if(!state.scaleEnabled()) state.toggleScale(); break; case 'w': printf("'w' should enable bouncing\n"); state.toggleTranslate(); break; case 'e': printf("'e' should enable z rotation\n"); // rotZ = true. state.toggleRotZ(); break; case 'r': printf("'r' should enable y rotation\n"); // rotY = true. state.toggleRotY(); break; default: printf("nothing\n"); break; } } // std::cout << "Your Input: " << static_cast<char>(event.key.code) << std::endl; //TODO add event handlers for qwer //'q' should scale //'w' should enable bouncing //'e' should enable z rotation //'r' should enable y rotation } }