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; }
int main(int argc, char *argv[]) { char *wmiirc; WMScreen *s; WinAttr wa; int i; fmtinstall('r', errfmt); fmtinstall('C', Cfmt); wmiirc = "wmiistartrc"; ARGBEGIN{ case 'v': print("%s", version); exit(0); case 'V': verbose = True; break; case 'a': address = EARGF(usage()); break; case 'r': wmiirc = EARGF(usage()); break; default: usage(); break; }ARGEND; if(argc) usage(); setlocale(LC_CTYPE, ""); starting = True; initdisplay(); xlib_errorhandler = XSetErrorHandler(errorhandler); check_other_wm = True; XSelectInput(display, scr.root.w, SubstructureRedirectMask | EnterWindowMask); XSync(display, False); check_other_wm = False; passwd = getpwuid(getuid()); user = estrdup(passwd->pw_name); init_environment(); sock = ixp_announce(address); if(sock < 0) fatal("Can't create socket '%s': %r", address); if(wmiirc) spawn_command(wmiirc); init_traps(); init_atoms(); init_cursors(); init_lock_keys(); srv.preselect = check_preselect; ixp_listen(&srv, sock, &p9srv, serve_9pcon, nil); ixp_listen(&srv, ConnectionNumber(display), nil, check_x_event, closedisplay); def.font = loadfont(FONT); def.border = 1; def.colmode = Coldefault; def.mod = Mod1Mask; strcpy(def.grabmod, "Mod1"); loadcolor(&def.focuscolor, FOCUSCOLORS); loadcolor(&def.normcolor, NORMCOLORS); num_screens = 1; screens = emallocz(num_screens * sizeof(*screens)); screen = &screens[0]; for(i = 0; i < num_screens; i++) { s = &screens[i]; init_screen(s); s->ibuf = allocimage(Dx(s->r), Dy(s->r), scr.depth); wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask; wa.cursor = cursor[CurNormal]; setwinattr(&scr.root, &wa, CWEventMask | CWCursor); initbar(s); } screen->focus = nil; setfocus(screen->barwin, RevertToParent); scan_wins(); starting = False; select_view("nil"); update_views(); write_event("FocusTag %s\n", screen->sel->name); check_x_event(nil); i = ixp_serverloop(&srv); if(i) fprint(2, "%s: error: %r\n", argv0); cleanup(); if(exitsignal) raise(exitsignal); if(execstr) execl("/bin/sh", "sh", "-c", execstr, nil); return i; }