void cyclelayout() { lt[sellt]++; if (lt[sellt] == layouts + LENGTH(layouts)) lt[sellt] = layouts; if(sel) arrange(); else drawbar(); }
void maximize(int x, int y, int w, int h) { XEvent ev; if(!selmon->sel || selmon->sel->isfixed) return; XRaiseWindow(dpy, selmon->sel->win); if(!selmon->sel->ismax) { if(!selmon->lt[selmon->sellt]->arrange || selmon->sel->isfloating) selmon->sel->wasfloating = True; else { togglefloating(NULL); selmon->sel->wasfloating = False; } selmon->sel->oldx = selmon->sel->x; selmon->sel->oldy = selmon->sel->y; selmon->sel->oldw = selmon->sel->w; selmon->sel->oldh = selmon->sel->h; resize(selmon->sel, x, y, w, h, True); selmon->sel->ismax = True; } else { resize(selmon->sel, selmon->sel->oldx, selmon->sel->oldy, selmon->sel->oldw, selmon->sel->oldh, True); if(!selmon->sel->wasfloating) togglefloating(NULL); selmon->sel->ismax = False; } drawbar(selmon); while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); }
void renderScene(void) { //float color[] ={1.0,1.0,1.0,1.0}; // clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_LIGHTING); // set the camera glLoadIdentity(); if (deltaMove) moveMeFlat(deltaMove); if (deltaUp) Lookup(deltaUp); if (deltaAngle) { angle += deltaAngle; orientMe(angle); } //float cam[3] = {x,y,z}; gluLookAt(x, y, z, x + lx,y + ly,z + lz, 0.0f,1.0f,0.0f); lightsON(); drawbar(); glutPostRedisplay(); // End of frame glutSwapBuffers(); }
int main(int argc, char *argv[]) { int sport, dport; char *nick; nick = NICK; if (argc < 4 || strcmp(argv[1], "-h") == 0) { fprintf(stderr, "%s host sport dport [nick]\n", argv[0]); return 1; } if (initui() == -1) bye(-1); drawbar("connecting..."); if (argc >= 5) nick = argv[4]; sserve = dial(argv[1], argv[2]); sbroad = dial(argv[1], argv[3]); if (sserve == -1 || sbroad == -1) return -1; loop(nick, argv[1]); bye(0); return 0; }
int main(int argc, char **argv) { int done, i; float theta, dt; float colors[3*10] = { 0.0f, 0.5f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f, 0.5f, 0.5f, 0.5f, 0.73f, 0.8f, 0.25f, 0.25f, 0.8f, 0.73f, 1.0f, 1.0f, 0.0f }; // Init PVR pvr_init_defaults(); // Setup the context plx_cxt_init(); plx_cxt_texture(NULL); plx_cxt_culling(PLX_CULL_NONE); // Until the user hits start... dt = 2*M_PI/160.0f; for (done = 0, theta = 0.0f; !done; ) { // Check for start MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st) if (st->buttons & CONT_START) done = 1; MAPLE_FOREACH_END() // Setup the frame pvr_wait_ready(); pvr_scene_begin(); pvr_list_begin(PVR_LIST_OP_POLY); // Submit the context plx_cxt_send(PVR_LIST_OP_POLY); // Draw a sinus bar at our current position and several positions // back. Each bar will get its own Z value (descending). for (i=0; i<10; i++) { drawbar(240.0f + fsin(theta - dt*i*6) * 120.0f, 100.0f - i, colors[i*3+0], colors[i*3+1], colors[i*3+2]); } pvr_scene_finish(); // Move our counters theta += dt; while (theta >= 2*M_PI) theta -= 2*M_PI; } return 0; }
void updateproc(void *v) { char *p, *f[2]; sleep(1000); while((p = Brdline(&b, '\n'))){ p[Blinelen(&b)-1] = '\0'; if(tokenize(p, f, 2) != 2) continue; n = strtoll(f[0], 0, 0); d = strtoll(f[1], 0, 0); if(!textmode){ lockdisplay(display); drawbar(); unlockdisplay(display); } else drawbar(); } threadexitsall("success"); }
void loop(char *nick, char *host) { fd_set rfs, wfs; FILE *fs, *fb; int hasline; int m; fs = fdopen(sserve, "r+"); fb = fdopen(sbroad, "r+"); # define max(a,b) ((a) > (b) ? (a) : (b)) m = max(sserve, sbroad); snprintf(wsay.b, sizeof(wsay.b)-2, "!iam %s\n", nick); hasline = 1; drawbar("connected as %s@%s\n", nick, host); for (;;) { fdset(&rfs, &wfs); if (select(m+1, &rfs, &wfs, NULL, NULL) == -1) { perror("select"); return; } if (FD_ISSET(sserve, &wfs)) if (hasline) { hasline = 0; if (say() < 0) return; redraw(); } if (FD_ISSET(0, &rfs)) hasline = peek(), redraw(); if (FD_ISSET(sserve, &rfs)) hear(sserve), redraw(); if (FD_ISSET(sbroad, &rfs)) hear(sbroad), redraw(); } }
void drawscreen(void) { Point l1, l2; int i; draw(screen, screen->r, brdr, nil, ZP); draw(screen, insetrect(screen->r, Border), background, nil, ZP); for(i = 0; i < Brdsize; i++) { l1 = addpt(screen->r.min, Pt(i*Square, Square)); l2 = addpt(screen->r.min, Pt(i*Square, Maxy)); line(screen, l1, l2, Endsquare, Endsquare, (i%3) == 0 ? Thickline : Line, brdr, ZP); l1 = addpt(screen->r.min, Pt(0, (i+1)*Square)); l2 = addpt(screen->r.min, Pt(Maxx, (i+1)*Square)); line(screen, l1, l2, Endsquare, Endsquare, (i%3) == 0 ? Thickline : Line, brdr, ZP); } for(i = 1; i < 10; i++) { drawbar(i, (selected == i) ? 1 : 0); } drawboard(); flushimage(display, 1); }
void resize() { Point p, q; Rectangle r; r = screen->r; draw(screen, r, light, nil, ZP); p = string(screen, addpt(r.min, Pt(4,4)), text, ZP, display->defaultfont, title); p.x = r.min.x+4; p.y += display->defaultfont->height+4; q = subpt(r.max, Pt(4,4)); rbar = Rpt(p, q); border(screen, rbar, -2, dark, ZP); last = 0; lastp = -1; flushimage(display, 1); drawbar(); }
int main (int argc, char **argv) { int done = 0; int paused = 0; struct timeval systime; char d; WINDOW *wnd; int nrows, ncols; int attrb; int docolor, nave; int opt; // options and defaults docolor = 0; nave = N_AVE; while ((opt = getopt (argc, argv, "bch")) != -1) switch (opt) { case 'c': docolor = 1; nave = N_AVE_COLOR; break; case 'h': printf("Usage: curses-benchmark [options]\n"); printf("Options:\n"); printf("-c use color\n"); printf("-h show this help\n"); return (0); } // init ncurses wnd = initscr (); cbreak (); noecho (); nodelay (wnd, TRUE); getmaxyx (wnd, nrows, ncols); start_color (); init_pair (1, COLOR_GREEN, COLOR_BLACK); init_pair (2, COLOR_YELLOW, COLOR_BLACK); init_pair (3, COLOR_RED, COLOR_BLACK); init_pair (4, COLOR_CYAN, COLOR_BLACK); init_pair (5, COLOR_MAGENTA, COLOR_BLACK); init_pair (6, COLOR_BLUE, COLOR_BLACK); init_pair (7, COLOR_WHITE, COLOR_BLACK); init_pair (8, COLOR_BLACK, COLOR_GREEN); init_pair (9, COLOR_BLACK, COLOR_CYAN); init_pair (10, COLOR_BLACK, COLOR_RED); init_pair (11, COLOR_BLACK, COLOR_MAGENTA); init_pair (12, COLOR_BLACK, COLOR_BLUE); init_pair (13, COLOR_BLACK, COLOR_WHITE); init_pair (14, COLOR_BLACK, COLOR_YELLOW); clear (); refresh (); // static displays attron(COLOR_PAIR(2)); drawline (1, ncols); drawline (nrows - 2, ncols); move (nrows - 1, 0); printw("type q to quit, c to toggle color, p to pause..."); attroff(COLOR_PAIR(2)); // main loop int r, c; int sec, us, secold, usold; double dt; long dk, k = -1, kold = -1; gettimeofday (&systime, NULL); secold = systime.tv_sec; usold = systime.tv_usec; while (!done) { ++k; if (!paused) { for (r = 2; r < nrows - 2; ++r) { move (r, 0); for (c = 0; c < ncols; ++c) { if (docolor) { attrb = random () & 0x0F00; attron (attrb); if ((random() & 0x1)) attron (A_BOLD); } addch ((random () & 0x3F) + 33); if (docolor) { attroff (attrb); attroff (A_BOLD); } } } } if (!(k % (nave/32))) { d = getch (); switch (d) { case 'q': done = 1; break; case 'p': paused = !paused; break; case 'c': docolor = !docolor; if (docolor) nave = N_AVE_COLOR; else nave = N_AVE; } drawbar ((double) (k % nave)/nave, 10, 0, 14); printw (" frames: %d", k); usleep (50000); } if (!(k % nave)) { gettimeofday (&systime, NULL); sec = systime.tv_sec; us = systime.tv_usec; dt = (double) (sec - secold) + (double) (us - usold)*1e-6; secold = sec; dk = k - kold; attron(COLOR_PAIR(1)); move (0, 0); clrtoeol (); printw ("fps: "); attron (A_BOLD); printw ("%.1f", (double) dk/ (double) dt); attroff (A_BOLD); attroff(COLOR_PAIR(1)); usold = us; kold = k; drawbar (0, 10, 0, 14); } refresh(); } endwin (); 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; }