void device_draw(gs_device_t *device, enum gs_draw_mode draw_mode, uint32_t start_vert, uint32_t num_verts) { struct gs_index_buffer *ib = device->cur_index_buffer; GLenum topology = convert_gs_topology(draw_mode); gs_effect_t *effect = gs_get_effect(); struct gs_program *program; if (!can_render(device)) goto fail; if (effect) gs_effect_update_params(effect); program = get_shader_program(device); if (!program) goto fail; load_vb_buffers(program, device->cur_vertex_buffer); if (program != device->cur_program && device->cur_program) { glUseProgram(0); gl_success("glUseProgram (zero)"); } if (program != device->cur_program) { device->cur_program = program; glUseProgram(program->obj); if (!gl_success("glUseProgram")) goto fail; } update_viewproj_matrix(device); program_update_params(program); if (ib) { if (num_verts == 0) num_verts = (uint32_t)device->cur_index_buffer->num; glDrawElements(topology, num_verts, ib->gl_type, (const GLvoid*)(start_vert * ib->width)); if (!gl_success("glDrawElements")) goto fail; } else { if (num_verts == 0) num_verts = (uint32_t)device->cur_vertex_buffer->num; glDrawArrays(topology, start_vert, num_verts); if (!gl_success("glDrawArrays")) goto fail; } return; fail: blog(LOG_ERROR, "device_draw (GL) failed"); }
void device_draw(device_t device, enum gs_draw_mode draw_mode, uint32_t start_vert, uint32_t num_verts) { struct gs_index_buffer *ib = device->cur_index_buffer; GLenum topology = convert_gs_topology(draw_mode); effect_t effect = gs_geteffect(); if (!can_render(device)) goto fail; if (effect) effect_updateparams(effect); shader_update_textures(device->cur_pixel_shader); update_viewproj_matrix(device); #ifdef _DEBUG if (!check_shader_pipeline_validity(device)) goto fail; #endif if (ib) { if (num_verts == 0) num_verts = (uint32_t)device->cur_index_buffer->num; glDrawElements(topology, num_verts, ib->gl_type, (const GLvoid*)(start_vert * ib->width)); if (!gl_success("glDrawElements")) goto fail; } else { if (num_verts == 0) num_verts = (uint32_t)device->cur_vertex_buffer->num; glDrawArrays(topology, start_vert, num_verts); if (!gl_success("glDrawArrays")) goto fail; } return; fail: blog(LOG_ERROR, "device_draw (GL) failed"); }
void display() { int i, wm; float size = 5; if (!can_render()) return; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (render_mode == IR) { /* draw the IR stuff */ glDisable(GL_LIGHTING); glBegin(GL_TRIANGLES); /* green center */ glColor3f(0.0, 1.0, 0.0); DRAW_TRIANGLE(width/2, height/2, 0, size); glEnd(); for (wm = 0; wm < MAX_WIIMOTES; ++wm) { glBegin(GL_TRIANGLES); /* red ir */ glColor3f(1.0, 0.0, 0.0); for (i = 0; i < 4; ++i) { if (wiimotes[wm]->ir.dot[i].visible) DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].rx, wiimotes[wm]->ir.dot[i].ry, 0, size); } /* yellow corrected ir */ glColor3f(1.0, 1.0, 0.0); for (i = 0; i < 4; ++i) { if (wiimotes[wm]->ir.dot[i].visible) DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].x, wiimotes[wm]->ir.dot[i].y, 0, size); } /* blue cursor */ glColor3f(0.0, 0.0, 1.0); DRAW_TRIANGLE(wiimotes[wm]->ir.x, wiimotes[wm]->ir.y-size, 0, size); glEnd(); } } else { /* draw the teapot */ gluLookAt(0.0, 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); update_light(GL_LIGHT0, &light); set_material(&red_plastic); glRotatef(wiimotes[0]->orient.roll, 0.0f, 0.0f, 1.0f); glRotatef(wiimotes[0]->orient.pitch, 1.0f, 0.0f, 0.0f); glutSolidTeapot(1); } SDL_GL_SwapBuffers(); }