static int camcamcam(struct s3d_evt *e) { struct s3d_obj_info *event; event =(struct s3d_obj_info*) e->buf; float zx,zy; if (!(strncmp(event->name, "sys_pointer0",12))) { if (butt) { printf("but %f %f %f\n", event->trans_x, event->trans_y, event->trans_z); mousex=((event->trans_x+1)/2)*t->cols; mousey=((event->trans_y+1)/2)*t->rows; updatemouse(); } } if (!(strncmp(event->name, "sys_cam",7))) { //( printf("%s | ,",event->name); printf("%f\n", event->scale); //) if (event->scale==1) zx=zy=1; else if (event->scale<1)//its tall { zx=1; zy=1/event->scale; } else if (event->scale>1) { zy=1; zx=event->scale; } zoomx=zx*12.5; zoomy=zy*10; yoom=zoomy/t->rows/26; xoom=zoomx/t->cols/13; // shooboogieman(t); // pokeboogieman(t); reshapeboogieman(t); dirty=1;// mainloop(); } return(0); }
int main() { inits(); Shader text_shader("text.vs", "text.frag"); Shader ourShader("coordinate_systems.vs", "coordinate_systems.frag"); Shader bar_shader("bar.vs", "bar.frag"); inittext(text_shader); initbar(bar_shader); // Set up our vertex data (and buffer(s)) and attribute pointers msg(sizeof(vertices_indexed)); msg(sizeof(indices)); msg(sizeof(vertices)); #ifdef use_indexed makeglgeom_indexed(VBO_indexed, VAO_indexed, EBO_indexed, vertices_indexed, indices, sizeof(vertices_indexed), sizeof(indices)); #else makeglgeom(VBO, VAO, vertices, sizeof(vertices)); #endif // Load and create a texture makegltext(texture1, "resources/textures/container.jpg"); makegltext(texture2, "resources/textures/awesomeface.png"); GLint modelLoc = glGetUniformLocation(ourShader.Program, "model"); GLint viewLoc = glGetUniformLocation(ourShader.Program, "view"); GLint projLoc = glGetUniformLocation(ourShader.Program, "projection"); // Game loop while (!glfwWindowShouldClose(window)) { // Set frame time GLfloat currentFrame = glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; #ifdef RAWMOUSE acc += updatemouse(); #endif //vec2 diff = mouse - acc; //log //mousepos += acc; lag = lag_coeff*acc; //lag = lag_coeff*vec2(log(abs(acc.x)), log(abs(acc.y))); //if (acc.x < 0)lag.x *= -1.0f; //if (acc.y < 0)lag.y *= -1.0f; if (abs(lag.x) < 1e-4) lag.x = 0; if (abs(lag.y) < 1e-4) lag.y = 0; acc -= lag; camera.ProcessMouseMovement(lag.x, lag.y); show2(mouse); show2(lag); show2(acc); //show2(string(int(0.1f*length(acc)), '=')); //show2(string(int(10.f*length(lag)), '=')); // Check and call events ####################################### glfwPollEvents(); Do_Movement(); // Clear the colorbuffer glClearColor(0.2f, 0.2f, 0.2f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // texts ####################### int line = 0; for (auto&a : texts) { RenderText(text_shader, a.first + " " + a.second, 25.0f, (line + 1)*25.0f, 0.3f, glm::vec3(1, 1, 1)); ++line; } //RenderText(text_shader, "(C) LearnOpenGL.com", 540.0f, 570.0f, 0.5f, glm::vec3(0.3, 0.7f, 0.9f)); drawbar(bar_shader); // Draw our first triangle ####################### ourShader.Use(); // Bind Textures using texture units ####################### glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture1); glUniform1i(glGetUniformLocation(ourShader.Program, "ourTexture1"), 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture2); glUniform1i(glGetUniformLocation(ourShader.Program, "ourTexture2"), 1); // Create camera transformation ####################### glm::mat4 view; view = camera.GetViewMatrix(); glm::mat4 projection; projection = glm::perspective(glm::radians(camera.Zoom), (float)screenWidth / (float)screenHeight, 0.1f, 1000.0f); // Get the uniform locations // Pass the matrices to the shader glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view)); glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection)); #ifdef use_indexed glBindVertexArray(VAO_indexed); #else glBindVertexArray(VAO); #endif for (GLuint i = 0; i < 10; i++) { // Calculate the model matrix for each object and pass it to shader before drawing glm::mat4 model; model = glm::translate(model, cubePositions[i]); GLfloat angle = 20.0f * i; model = glm::rotate(model, angle, glm::vec3(1.0f, 0.3f, 0.5f)); glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); #ifdef use_indexed glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0); #else glDrawArrays(GL_TRIANGLES, 0, 36); #endif } glBindVertexArray(0); // Swap the buffers glfwSwapBuffers(window); } // Properly de-allocate all resources once they've outlived their purpose glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &VBO); glfwTerminate(); ManyMouse_Quit(); return 0; }