bool RenderHead( float angle, bool shadow, bool lighting, void *result, int width, int height, void *head, int headWidth, int headHeight, void *helm, int helmWidth, int helmHeight) { OSMesaContext ctx = init_osmesa(width, height, result); if (ctx) { // Initialize OpenGL init_gl(width, height); // Upload helm upload_image(1, head, headWidth, headHeight); if (helm) upload_image(2, helm, helmWidth, helmHeight); if (shadow) setup_shadow(angle); glEnable(GL_TEXTURE_2D); if (lighting) setup_lighting(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3f(1.0f, 1.0f, 1.0f); glBindTexture(GL_TEXTURE_2D, 1); draw(1.0f, 1.0f, 1.0f, angle); if (helm) { glBindTexture(GL_TEXTURE_2D, 2); draw(1.05f, 1.05f, 1.05f, angle); } glFinish(); OSMesaDestroyContext(ctx); return true; } return false; }
void VoxelEditor::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glEnable(GL_DEPTH_TEST); view_matrix = mat4(); view_matrix = glm::translate(view_matrix, vec3(width() / 2, height() / 2, 0.0f)); view_matrix = glm::translate(view_matrix, pos); view_matrix = glm::scale(view_matrix, vec3(scale, scale, scale)); view_matrix = glm::rotate(view_matrix, rotate_x, vec3(1.0f, 0.0f, 0.0f)); view_matrix = glm::rotate(view_matrix, rotate_z, vec3(0.0f, 0.0f, 1.0f)); mvp = projection_matrix * view_matrix; inverse_mvp = glm::inverse(mvp); multiply_matrix(view_matrix); glEnable(GL_LIGHTING); setup_lighting(); model->draw_immediate(); SelectedVoxels::const_iterator it; for (it = selected_list.begin(); it != selected_list.end(); it++) { const SelectedVoxel & v = *it; RGBColor & c = global_palette[v.v]; draw_cube(v.x, v.y, v.z, v.x + 1.0f, v.y + 1.0f, v.z + 1.0f, c.r, c.g, c.b, 255); glDisable(GL_LIGHTING); draw_wireframe_cube(v.x, v.y, v.z, v.x + 1.0f, v.y + 1.0f, v.z + 1.0f, 255, 255, 255, 255); glEnable(GL_LIGHTING); } glDisable(GL_LIGHTING); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); vec3 min = voxel->get_min(); vec3 max = voxel->get_max(); float x1 = min.x; float x2 = max.x; float y1 = min.y; float y2 = max.y; float z1 = min.z; float z2 = max.z; draw_wireframe_cube(x1, y1, z1, x2, y2, z2, 255, 255, 255, 255); // checkerboard glNormal3f(0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); for (int x = 0; x < voxel->x_size; x++) for (int y = 0; y < voxel->y_size; y++) { float gl_x1 = x1 + float(x); float gl_x2 = gl_x1 + 1.0f; float gl_y1 = y1 + float(y); float gl_y2 = gl_y1 + 1.0f; unsigned char r, g, b; if ((x + y) % 2 == 0) r = g = b = 100; else r = g = b = 180; glColor4ub(r, g, b, 255); glVertex3f(gl_x1, gl_y1, z1 - 0.01f); glVertex3f(gl_x2, gl_y1, z1 - 0.01f); glVertex3f(gl_x2, gl_y2, z1 - 0.01f); glVertex3f(gl_x1, gl_y2, z1 - 0.01f); } glEnd(); // draw axis lines glLineWidth(1.0f); glBegin(GL_LINES); glColor4ub(GREY_R, GREY_G, GREY_B, 255); glVertex3f(-COORD_LINE_SIZE, 0.0f, 0.0f); glVertex3f(0, 0.0f, 0.0f); glVertex3f(0.0f, -COORD_LINE_SIZE, 0.0f); glVertex3f(0.0f, 0, 0.0f); glColor4ub(RED_R, RED_G, RED_B, 255); glVertex3f(0, 0.0f, 0.0f); glVertex3f(COORD_LINE_SIZE, 0.0f, 0.0f); glColor4ub(BLUE_R, BLUE_G, BLUE_B, 255); glVertex3f(0.0f, 0, 0.0f); glVertex3f(0.0f, COORD_LINE_SIZE, 0.0f); glColor4ub(GREEN_R, GREEN_G, GREEN_B, 255); glVertex3f(0.0f, 0.0f, 0); glVertex3f(0.0f, 0.0f, COORD_LINE_SIZE); glEnd(); glDisable(GL_DEPTH_TEST); if (selected_list.size() > 0) pos_arrows.draw(); if (window->test_current_window(this)) { ReferencePoint * ref = window->model_properties->get_point(); if (ref != NULL) { float x, y, z; x = float(ref->x); y = float(ref->y); z = float(ref->z); draw_cube(x, y, z, 0.5f, 127, 127, 127, 127); draw_cube(x, y, z, 0.2f, 0, 0, 255, 255); } } glColor4f(1.0f, 1.0f, 1.0f, 1.0f); }
void setup_scene(){ setup_lighting(); STATE = S_SIMULATION; }