static void glutDisplayCallback(void) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_LINES); glVertex2f(cursor_x, cursor_y); glVertex2f(window_width/2, window_height/2); glEnd(); glutDrawString(16, 16, "Hello GLUT"); glutSwapBuffers(); }
void GLUTSimLightController::draw() { int w = glutGet(GLUT_WINDOW_WIDTH); int h = glutGet(GLUT_WINDOW_HEIGHT); float light_position[4] = {0.0, 0.0, -1.0, 0.0}; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(35, (double) w/h, 0.1, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glTranslatef(0, 0, -3); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1); glEnable(GL_DEPTH_TEST); glEnable(GL_POINT_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); struct Light { float radius; float color[3]; float position[2]; } lights[4] = { { .2, { 0, 0,.8 }, { -.5, -.5 } }, { .2, { .8, 0, 0 }, { .5, -.5 } }, { .2, { 0,.8, 0 }, { .5, .5 } }, { .2, { .9,.9,.9 }, { -.5, .5 } }, }; for (unsigned i = 0; i != 4; ++i) { Light &l = lights[i]; if (lights_enabled[i]) { glColor3fv(l.color); draw_circle_filled(l.position[0], l.position[1], l.radius); } } // Draw the beat monitor. const double beat_monitor_dim_time = .05; double elapsed = get_elapsed_time_in_seconds(); if (elapsed - last_beat_time <= beat_monitor_dim_time) { double v = 1 - (elapsed - last_beat_time) / beat_monitor_dim_time; glColor3f(v, v, v); glRectf(-.9, -.9, -.7, -.8); } // Draw the 2D overlays. glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, w, 0, h, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); const int textHeight = 15; char buffer[256]; int y = 0; sprintf(buffer, "Time: %.4fs\n", elapsed); glColor3f(1, 1, 1); glutDrawString(10, 10 + textHeight*y++, buffer); if (true) { num_frames++; double fps = num_frames / elapsed; sprintf(buffer, "FPS: %.4fs\n", fps); glColor3f(1, 1, 1); glutDrawString(10, 10 + textHeight*y++, buffer); } if (light_manager) { double bpm = light_manager->GetRecentBPM(); sprintf(buffer, "BPM: %.4fs\n", bpm); glColor3f(1, 1, 1); glutDrawString(10, 10 + textHeight*y++, buffer); } if (light_manager) { sprintf(buffer, "Program: %s\n", light_manager->GetProgramName().c_str()); glColor3f(1, 1, 1); glutDrawString(10, 10 + textHeight*y++, buffer); } if (light_manager) { sprintf(buffer, "Strobe Enabled: %s\n", light_manager->GetStrobeEnabled() ? "yes" : "no"); glColor3f(1, 1, 1); glutDrawString(10, 10 + textHeight*y++, buffer); } glFlush(); glutSwapBuffers(); }