void CL_RenderBatch3D::flush(CL_GraphicContext &gc) { if (position > 0) { gc.set_modelview(CL_Mat4f::identity()); gc.set_program_object(cl_program_sprite); if (use_glyph_program) { CL_BlendMode old_blend_mode = gc.get_blend_mode(); CL_BlendMode blend_mode; blend_mode.set_blend_color(constant_color); blend_mode.set_blend_function(cl_blend_constant_color, cl_blend_one_minus_src_color, cl_blend_zero, cl_blend_one); gc.set_blend_mode(blend_mode); for (int i = 0; i < num_current_textures; i++) gc.set_texture(i, current_textures[i]); CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, &vertices[0].position, sizeof(SpriteVertex)); prim_array.set_attributes(1, &vertices[0].color, sizeof(SpriteVertex)); prim_array.set_attributes(2, &vertices[0].texcoord, sizeof(SpriteVertex)); prim_array.set_attributes(3, &vertices[0].texindex, sizeof(SpriteVertex)); gc.draw_primitives(cl_triangles, position, prim_array); for (int i = 0; i < num_current_textures; i++) gc.reset_texture(i); gc.set_blend_mode(old_blend_mode); } else { for (int i = 0; i < num_current_textures; i++) gc.set_texture(i, current_textures[i]); CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, &vertices[0].position, sizeof(SpriteVertex)); prim_array.set_attributes(1, &vertices[0].color, sizeof(SpriteVertex)); prim_array.set_attributes(2, &vertices[0].texcoord, sizeof(SpriteVertex)); prim_array.set_attributes(3, &vertices[0].texindex, sizeof(SpriteVertex)); gc.draw_primitives(cl_triangles, position, prim_array); for (int i = 0; i < num_current_textures; i++) gc.reset_texture(i); } gc.reset_program_object(); gc.set_modelview(modelview); position = 0; for (int i = 0; i < num_current_textures; i++) current_textures[i] = CL_Texture(); num_current_textures = 0; } }
void App::draw_texture(CL_GraphicContext &gc, const CL_Rectf &rect, const CL_Colorf &color, const CL_Rectf &texture_unit1_coords) { CL_Vec2f positions[6] = { CL_Vec2f(rect.left, rect.top), CL_Vec2f(rect.right, rect.top), CL_Vec2f(rect.left, rect.bottom), CL_Vec2f(rect.right, rect.top), CL_Vec2f(rect.left, rect.bottom), CL_Vec2f(rect.right, rect.bottom) }; CL_Vec2f tex1_coords[6] = { CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.bottom) }; CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, positions); prim_array.set_attribute(1, color); prim_array.set_attributes(2, tex1_coords); gc.draw_primitives(cl_triangles, 6, prim_array); }
void CL_Draw::gradient_fill(CL_GraphicContext &gc, float x1, float y1, float x2, float y2, const CL_Gradient &gradient) { CL_Vec2f positions[6] = { CL_Vec2f(x1, y1), CL_Vec2f(x2, y1), CL_Vec2f(x1, y2), CL_Vec2f(x2, y1), CL_Vec2f(x1, y2), CL_Vec2f(x2, y2) }; #define cl_color_to_color4d(c) c.get_red(), c.get_green(), c.get_blue(), c.get_alpha() CL_Vec4f colors[6] = { CL_Vec4f(cl_color_to_color4d(gradient.top_left)), CL_Vec4f(cl_color_to_color4d(gradient.top_right)), CL_Vec4f(cl_color_to_color4d(gradient.bottom_left)), CL_Vec4f(cl_color_to_color4d(gradient.top_right)), CL_Vec4f(cl_color_to_color4d(gradient.bottom_left)), CL_Vec4f(cl_color_to_color4d(gradient.bottom_right)) }; CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, positions); prim_array.set_attributes(1, colors); gc.set_program_object(cl_program_color_only); gc.draw_primitives(cl_triangles, 6, prim_array); gc.reset_program_object(); }
/** * Draws the polygon on the graphics context. * * @param gc Graphics context to draw the polygon on. */ void Polygon::draw(CL_GraphicContext gc) { //Only draw if more than one point exists. if(_points.size() > 1) { //CL_Vec4f green_color(1.0f, 1.0f, 1.0f, 1.0f); CL_Vec2i points_array[_points.size()]; std::list<CL_Pointf>::iterator it_point; int n = 0; for(it_point = _points.begin(); it_point != _points.end(); ++it_point) { points_array[n] = static_cast<CL_Vec2i>(*(it_point)); n++; } CL_PrimitivesArray poly(gc); poly.set_attributes(0, points_array); poly.set_attribute(1, _line_color); //scene->get_world()->get_gc()->get_polygon_rasterizer().set_face_fill_mode_front(cl_fill_polygon); gc.set_program_object(cl_program_color_only); gc.draw_primitives(cl_line_loop,n,poly); gc.reset_program_object(); } }
void Model_Impl::Draw(CL_GraphicContext &gc, GraphicStore *gs, const CL_Mat4f &modelview_matrix) { gc.set_modelview(modelview_matrix); CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, vbo_positions, 3, cl_type_float, (void *) 0); prim_array.set_attributes(1, vbo_normals, 3, cl_type_float, (void *) 0); if (!vbo_texcoords.is_null()) { prim_array.set_attributes(2, vbo_texcoords, 2, cl_type_float, (void *) 0); gc.set_texture(0, gs->texture_underwater); gc.set_texture(1, gs->texture_background); gs->shader_texture.SetMaterial(material_shininess, material_emission, material_ambient, material_specular); gs->shader_texture.Use(gc); } else { throw CL_Exception("What! no texure coordinates?"); } gc.draw_primitives(cl_triangles, vbo_size, prim_array); gc.reset_texture(0); gc.reset_texture(0); }
void CL_Draw::point(CL_GraphicContext &gc, float x1, float y1, const CL_Colorf &color) { CL_Vec2f positions[1] = { CL_Vec2f(x1, y1) }; CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, positions); prim_array.set_attribute(1, color); gc.set_program_object(cl_program_color_only); gc.draw_primitives(cl_points, 1, prim_array); gc.reset_program_object(); }
void Model_Impl::Draw(CL_GraphicContext &gc, GraphicStore *gs, const CL_Mat4f &modelview_matrix, bool is_draw_shadow) { gc.set_modelview(modelview_matrix); CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, vbo_positions, 3, cl_type_float, (void *) 0); prim_array.set_attributes(1, vbo_normals, 3, cl_type_float, (void *) 0); if (is_draw_shadow) { gs->shader_depth.Use(gc); gc.draw_primitives(cl_triangles, vbo_size, prim_array); } else { if (!vbo_texcoords.is_null()) { prim_array.set_attributes(2, vbo_texcoords, 2, cl_type_float, (void *) 0); gs->shader_texture.SetShadowMatrix(gs->shadow_matrix); gc.set_texture(0, gs->texture_brick); gc.set_texture(1, gs->texture_shadow); gs->shader_texture.SetMaterial(material_shininess, material_emission, material_ambient, material_specular); gs->shader_texture.Use(gc); } else { gs->shader_color.SetMaterial(material_shininess, material_emission, material_ambient, material_specular); gs->shader_color.Use(gc); } gc.draw_primitives(cl_triangles, vbo_size, prim_array); gc.reset_texture(0); gc.reset_texture(1); } }
void Model_Impl::Draw(CL_GraphicContext &gc, GraphicStore *gs, const CL_Mat4f &modelview_matrix) { gc.set_modelview(modelview_matrix); CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, vbo_positions, 3, cl_type_float, (void *) 0); prim_array.set_attributes(1, vbo_normals, 3, cl_type_float, (void *) 0); gs->shader_color.SetMaterial(material_shininess, material_emission, material_ambient, material_specular); gs->shader_color.Use(gc); gc.draw_primitives(cl_triangles, vbo_size, prim_array); }
void CL_Draw::triangle(CL_GraphicContext &gc, const CL_Pointf &a, const CL_Pointf &b, const CL_Pointf &c, const CL_Colorf &color) { CL_Vec2f positions[3] = { CL_Vec2f(a.x, a.y), CL_Vec2f(b.x, b.y), CL_Vec2f(c.x, c.y) }; CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, positions); prim_array.set_attribute(1, color); gc.set_program_object(cl_program_color_only); gc.draw_primitives(cl_triangles, 3, prim_array); gc.reset_program_object(); }
void App::draw(CL_GraphicContext &gc, const CL_Rectf &rect) { CL_Vec2f positions[6] = { CL_Vec2f(rect.left, rect.top), CL_Vec2f(rect.right, rect.top), CL_Vec2f(rect.left, rect.bottom), CL_Vec2f(rect.right, rect.top), CL_Vec2f(rect.left, rect.bottom), CL_Vec2f(rect.right, rect.bottom) }; CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, positions); gc.draw_primitives(cl_triangles, 6, prim_array); }
void CL_Draw::box(CL_GraphicContext &gc, float x1, float y1, float x2, float y2, const CL_Colorf &color) { CL_Vec2f positions[4] = { CL_Vec2f(x1, y1), CL_Vec2f(x2, y1), CL_Vec2f(x2, y2), CL_Vec2f(x1, y2) }; CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, positions); prim_array.set_attribute(1, color); gc.set_program_object(cl_program_color_only); gc.draw_primitives(cl_line_loop, 4, prim_array); gc.reset_program_object(); }
void Skybox::render(CL_GraphicContext &gc, const Camera &camera) { Camera cam = camera; cam.get_position().set_position(0,0,0); cam.setup_gc(gc, 0.1f, 10.0f); gc.set_texture(0, skybox_texture); gc.set_program_object(program_object); program_object.set_uniform1i(("texture1"), 0); CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, positions); gc.draw_primitives(cl_triangles, 6*6, prim_array); gc.reset_program_object(); gc.reset_texture(0); }
void HSVSpriteBatch::flush(CL_GraphicContext &gc) { if (fill_position > 0) { CL_PrimitivesArray primarray(gc); primarray.set_attributes(0, positions); primarray.set_attributes(1, hue_offsets); primarray.set_attributes(2, tex1_coords); gc.set_texture(0, current_texture); gc.set_program_object(program, cl_program_matrix_modelview_projection); gc.draw_primitives(cl_triangles, fill_position, primarray); gc.reset_program_object(); gc.reset_texture(0); fill_position = 0; current_texture = CL_Texture(); } }
void ShaderImpl::end(CL_GraphicContext &p_gc) { G_ASSERT(m_initialized); G_ASSERT(m_began); // detach frame buffer p_gc.reset_frame_buffer(); m_frameBuffer.detach_color_buffer(0, m_texture); // prepare shader m_program.set_uniform1i("tex", 0); m_program.set_uniform1i("textureWidth", m_drawRect.get_width()); m_program.set_uniform1i("textureHeight", m_drawRect.get_height()); m_parent->setUniforms(m_program); // draw texture using shader p_gc.set_modelview(CL_Mat4f::identity()); p_gc.mult_translate(m_drawRect.left, m_drawRect.top); p_gc.mult_scale(m_drawRect.get_width(), m_drawRect.get_height()); p_gc.set_texture(0, m_texture); p_gc.set_program_object(m_program); p_gc.draw_primitives(cl_quads, 4, m_quad); p_gc.reset_program_object(); p_gc.reset_texture(0); #if defined(DRAW_WIREFRAME) CL_Draw::line(p_gc, 0, 0, 1, 0, CL_Colorf::red); CL_Draw::line(p_gc, 1, 0, 1, 1, CL_Colorf::red); CL_Draw::line(p_gc, 1, 1, 0, 1, CL_Colorf::red); CL_Draw::line(p_gc, 0, 1, 0, 0, CL_Colorf::red); #endif // DRAW_WIREFRAME // reset modelview matrix p_gc.pop_modelview(); m_began = false; }
void CL_Draw::texture( CL_GraphicContext &gc, const CL_Texture &texture, const CL_Quadf &quad, const CL_Colorf &color, const CL_Rectf &texture_unit1_coords) { CL_Vec2f positions[6] = { CL_Vec2f(quad.p), CL_Vec2f(quad.q), CL_Vec2f(quad.s), CL_Vec2f(quad.q), CL_Vec2f(quad.s), CL_Vec2f(quad.r) }; CL_Vec2f tex1_coords[6] = { CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.bottom) }; CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, positions); prim_array.set_attribute(1, color); prim_array.set_attributes(2, tex1_coords); gc.set_texture(0, texture); gc.set_program_object(cl_program_single_texture); gc.draw_primitives(cl_triangles, 6, prim_array); gc.reset_program_object(); gc.reset_texture(0); }
void HSV::render_texture(CL_GraphicContext &gc, CL_ProgramObject &program, CL_Texture &texture, float hue_offset) { CL_Rectf rect(0.0f, 0.0f, (float)gc.get_width(), (float)gc.get_height()); CL_Rectf texture_unit1_coords(0.0f, 0.0f, 1.0f, 1.0f); CL_Vec2f positions[6] = { CL_Vec2f(rect.left, rect.top), CL_Vec2f(rect.right, rect.top), CL_Vec2f(rect.left, rect.bottom), CL_Vec2f(rect.right, rect.top), CL_Vec2f(rect.left, rect.bottom), CL_Vec2f(rect.right, rect.bottom) }; CL_Vec2f tex1_coords[6] = { CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.bottom) }; CL_PrimitivesArray primarray(gc); primarray.set_attributes(0, positions); primarray.set_attribute(1, CL_Vec1f(hue_offset)); primarray.set_attributes(2, tex1_coords); gc.set_texture(0, texture); gc.set_program_object(program, cl_program_matrix_modelview_projection); gc.draw_primitives(cl_triangles, 6, primarray); gc.reset_program_object(); gc.reset_texture(0); }
// The start of the Application int App::start(const std::vector<CL_String> &args) { CL_DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_title("Vertex Buffer Object Example"); win_desc.set_depth_size(16); win_desc.set_size(CL_Size( 800, 600 ), false); CL_DisplayWindow window(win_desc); CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up); CL_GraphicContext gc = window.get_gc(); Shader shader(gc); // Prepare the display gc.set_map_mode(cl_user_projection); CL_PolygonRasterizer polygon_rasterizer; polygon_rasterizer.set_culled(true); polygon_rasterizer.set_face_cull_mode(cl_cull_back); polygon_rasterizer.set_front_face(cl_face_side_clockwise); gc.set_polygon_rasterizer(polygon_rasterizer); CL_BufferControl buffer_control; buffer_control.enable_depth_test(true); buffer_control.set_depth_compare_function(cl_comparefunc_lequal); buffer_control.enable_depth_write(true); gc.set_buffer_control(buffer_control); std::vector<CL_Vec3f> object_positions; std::vector<CL_Vec3f> object_normals; std::vector<CL_Vec4f> object_material_ambient; const int num_cubes = 20000; object_positions.reserve(num_cubes * 6 * 6); // 6 faces, and 6 vertices per face object_normals.reserve(num_cubes * 6 * 6); object_material_ambient.reserve(num_cubes * 6 * 6); for (int cnt=0; cnt < num_cubes; cnt++) { create_cube(object_positions, object_normals, object_material_ambient); } CL_VertexArrayBuffer vb_positions(gc, &object_positions[0], sizeof(CL_Vec3f) * object_positions.size()); CL_VertexArrayBuffer vb_normals(gc, &object_normals[0], sizeof(CL_Vec3f) * object_normals.size()); CL_VertexArrayBuffer vb_material_ambient(gc, &object_material_ambient[0], sizeof(CL_Vec4f) * object_material_ambient.size()); // ** Note, at this point "object_positions, object_normals and object_material_ambient" // ** can be destroyed. But for the purpose of this example, is it kept CL_Font fps_font(gc, "tahoma", 20); FramerateCounter frameratecounter; unsigned int time_last = CL_System::get_time(); float angle = 0.0f; is_vertex_buffer_on = true; while (!quit) { unsigned int time_now = CL_System::get_time(); float time_diff = (float) (time_now - time_last); time_last = time_now; gc.clear(CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f)); gc.clear_depth(1.0f); gc.set_map_mode(cl_map_2d_upper_left); CL_String fps = cl_format("%1 fps", frameratecounter.get_framerate()); fps_font.draw_text(gc, gc.get_width() - 100, 30, fps); CL_String info = cl_format("%1 vertices", (int) object_positions.size()); fps_font.draw_text(gc, 30, 30, info); fps_font.draw_text(gc, 30, gc.get_height() - 8, "Press any key to toggle the Vertex Buffer option"); if (is_vertex_buffer_on) { fps_font.draw_text(gc, 200, 30, "Vertex Buffer = ON"); } else { fps_font.draw_text(gc, 200, 30, "Vertex Buffer = OFF"); } gc.set_map_mode(cl_user_projection); CL_Mat4f perp = CL_Mat4f::perspective(45.0f, ((float) gc.get_width()) / ((float) gc.get_height()), 0.1f, 100000.0f); gc.set_projection(perp); angle += time_diff / 20.0f; if (angle >= 360.0f) angle -= 360.0f; gc.push_modelview(); gc.set_modelview(CL_Mat4f::identity()); gc.mult_scale(1.0f,1.0f, -1.0f); // So +'ve Z goes into the screen gc.mult_translate(0.0f, 0.0f, 800.0f); gc.mult_rotate(CL_Angle(angle*2.0f, cl_degrees), 0.0f, 1.0f, 0.0f, false); gc.mult_rotate(CL_Angle(angle, cl_degrees), 1.0f, 0.0f, 0.0f, false); shader.Set(gc); shader.Use(gc); CL_PrimitivesArray prim_array(gc); if (is_vertex_buffer_on) { prim_array.set_attributes(0, vb_positions, 3, cl_type_float, (void *) 0); prim_array.set_attributes(1, vb_normals, 3, cl_type_float, (void *) 0); prim_array.set_attributes(2, vb_material_ambient, 4, cl_type_float, (void *) 0); } else { prim_array.set_attributes(0, &object_positions[0]); prim_array.set_attributes(1, &object_normals[0]); prim_array.set_attributes(2, &object_material_ambient[0]); } gc.draw_primitives(cl_triangles, object_positions.size(), prim_array); gc.pop_modelview(); gc.reset_program_object(); window.flip(0); frameratecounter.frame_shown(); CL_KeepAlive::process(); } return 0; }
void ContainerRenderer::render(CL_GraphicContext& gc) { renderQueue_->preRender(); gc.clear(CL_Colorf(0.f, 0.f, 0.f, 0.f)); boost::shared_ptr<CL_ProgramObject> shader = ui::Manager::getShaderManager()->getGumpShader(); gc.set_program_object(*shader, cl_program_matrix_modelview_projection); CL_Texture huesTexture = data::Manager::getHuesLoader()->getHuesTexture(); gc.set_texture(0, huesTexture); // set texture unit 1 active to avoid overriding the hue texture with newly loaded object textures gc.set_texture(1, huesTexture); shader->set_uniform1i("HueTexture", 0); shader->set_uniform1i("ObjectTexture", 1); RenderQueue::const_iterator igIter = renderQueue_->begin(); RenderQueue::const_iterator igEnd = renderQueue_->end(); CL_Vec2f vertexCoords[6]; bool renderingComplete = true; // draw background container texture boost::shared_ptr<ui::Texture> bgTex = containerView_->getBackgroundTexture(); if (bgTex && bgTex->isReadComplete()) { CL_Vec3f hueInfo(0, 0, 1); CL_Rectf rect(0, 0, CL_Sizef(bgTex->getWidth(), bgTex->getHeight())); vertexCoords[0] = CL_Vec2f(rect.left, rect.top); vertexCoords[1] = CL_Vec2f(rect.right, rect.top); vertexCoords[2] = CL_Vec2f(rect.left, rect.bottom); vertexCoords[3] = CL_Vec2f(rect.right, rect.top); vertexCoords[4] = CL_Vec2f(rect.left, rect.bottom); vertexCoords[5] = CL_Vec2f(rect.right, rect.bottom); CL_Rectf texCoordHelper = bgTex->getNormalizedTextureCoords(); CL_Vec2f texCoords[6] = { CL_Vec2f(texCoordHelper.left, texCoordHelper.top), CL_Vec2f(texCoordHelper.right, texCoordHelper.top), CL_Vec2f(texCoordHelper.left, texCoordHelper.bottom), CL_Vec2f(texCoordHelper.right, texCoordHelper.top), CL_Vec2f(texCoordHelper.left, texCoordHelper.bottom), CL_Vec2f(texCoordHelper.right, texCoordHelper.bottom) }; CL_PrimitivesArray primarray(gc); primarray.set_attributes(0, vertexCoords); primarray.set_attributes(1, texCoords); primarray.set_attribute(2, hueInfo); gc.set_texture(1, bgTex->getTexture()); gc.draw_primitives(cl_triangles, 6, primarray); } else { renderingComplete = false; } for (; igIter != igEnd; ++igIter) { boost::shared_ptr<world::IngameObject> curObj = *igIter; // just items in a container if (!curObj->isDynamicItem()) { continue; } // check if texture is ready to be drawn boost::shared_ptr<ui::Texture> tex = curObj->getIngameTexture(); if (!tex) { continue; } if (!tex->isReadComplete()) { renderingComplete = false; continue; } CL_Rectf rect(curObj->getLocXDraw(), curObj->getLocYDraw(), CL_Sizef(tex->getWidth(), tex->getHeight())); vertexCoords[0] = CL_Vec2f(rect.left, rect.top); vertexCoords[1] = CL_Vec2f(rect.right, rect.top); vertexCoords[2] = CL_Vec2f(rect.left, rect.bottom); vertexCoords[3] = CL_Vec2f(rect.right, rect.top); vertexCoords[4] = CL_Vec2f(rect.left, rect.bottom); vertexCoords[5] = CL_Vec2f(rect.right, rect.bottom); CL_Rectf texCoordHelper = tex->getNormalizedTextureCoords(); CL_Vec2f texCoords[6] = { CL_Vec2f(texCoordHelper.left, texCoordHelper.top), CL_Vec2f(texCoordHelper.right, texCoordHelper.top), CL_Vec2f(texCoordHelper.left, texCoordHelper.bottom), CL_Vec2f(texCoordHelper.right, texCoordHelper.top), CL_Vec2f(texCoordHelper.left, texCoordHelper.bottom), CL_Vec2f(texCoordHelper.right, texCoordHelper.bottom) }; CL_PrimitivesArray primarray(gc); primarray.set_attributes(0, vertexCoords); primarray.set_attributes(1, texCoords); primarray.set_attribute(2, curObj->getHueInfo(false)); gc.set_texture(1, tex->getTexture()); gc.draw_primitives(cl_triangles, 6, primarray); } gc.reset_textures(); gc.reset_program_object(); renderQueue_->postRender(renderingComplete); if (!renderingComplete) { ui::Manager::getSingleton()->queueComponentRepaint(containerView_); } }
void Model_Impl::Draw(CL_GraphicContext &gc, GraphicStore *gs, const CL_Mat4f &modelview_matrix, bool use_geometry_shader) { if (!object_positions.size()) return; if (update_vbo) { update_vbo = false; if (object_texcoords.size()) { object_texcoords_vbo = CL_VertexArrayBuffer(gc, &object_texcoords[0], sizeof(CL_Vec2f) * object_texcoords.size()); } object_positions_vbo = CL_VertexArrayBuffer(gc, &object_positions[0], sizeof(CL_Vec3f) * object_positions.size()); object_normals_vbo = CL_VertexArrayBuffer(gc, &object_normals[0], sizeof(CL_Vec3f) * object_normals.size()); } gc.set_modelview(modelview_matrix); CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, object_positions_vbo, 3, cl_type_float, (void *) 0); prim_array.set_attributes(1, object_normals_vbo, 3, cl_type_float, (void *) 0); if (!use_geometry_shader) { if (object_texcoords.size()) { prim_array.set_attributes(2, object_texcoords_vbo, 2, cl_type_float, (void *) 0); gc.set_texture(0, gs->texture_brick); gs->shader_texture.SetMaterial(material_shininess, material_emission, material_ambient, material_specular); gs->shader_texture.Use(gc); } else { gs->shader_color.SetMaterial(material_shininess, material_emission, material_ambient, material_specular); gs->shader_color.Use(gc); } } else { if (object_texcoords.size()) throw CL_Exception("Shader not supported"); gs->shader_color_geometry.SetMaterial(material_shininess, material_emission, material_ambient, material_specular); gs->shader_color_geometry.Use(gc); clDisable(CL_CULL_FACE); // For for example, so you can see inside the teapot } gc.draw_primitives(cl_triangles, object_positions.size(), prim_array); if (use_geometry_shader) clEnable(CL_CULL_FACE); if (object_texcoords.size()) { gc.reset_texture(0); } }
void CL_Draw::gradient_circle(CL_GraphicContext &gc, const CL_Pointf ¢er, const CL_Pointf ¢ergradient, float radius, const CL_Gradient &gradient) { float offset_x = 0; float offset_y = 0; if(radius < 4) radius = 4; float rotationcount = (radius - 3); float halfpi = 1.5707963267948966192313216916398f; float turn = halfpi / rotationcount; if(center.distance(center + centergradient) < radius) { offset_x = centergradient.x; offset_y = -centergradient.y; } CL_Vec4f colors[3] = { CL_Vec4f(gradient.top_left.get_red(), gradient.top_left.get_green(), gradient.top_left.get_blue(), gradient.top_left.get_alpha()), CL_Vec4f(gradient.bottom_right.get_red(), gradient.bottom_right.get_green(), gradient.bottom_right.get_blue(), gradient.bottom_right.get_alpha()), CL_Vec4f(gradient.bottom_right.get_red(), gradient.bottom_right.get_green(), gradient.bottom_right.get_blue(), gradient.bottom_right.get_alpha()) }; CL_Vec4f triangle_colors[4*3]; for (int i=0; i<3; i++) { triangle_colors[0*3+i] = colors[i]; triangle_colors[1*3+i] = colors[i]; triangle_colors[2*3+i] = colors[i]; triangle_colors[3*3+i] = colors[i]; } for(float i = 0; i < rotationcount ; i++) { float pos1 = cos(i * turn); float pos2 = sin(i * turn); float pos3 = cos((i+1) * turn); float pos4 = sin((i+1) * turn); CL_Vec2f positions[4*3] = { // 90 triangle: CL_Vec2f(center.x + offset_x , center.y + offset_y), CL_Vec2f(center.x + ((float)radius * pos1), center.y + ((float)radius * pos2)), CL_Vec2f(center.x + ((float)radius * pos3), center.y + ((float)radius * pos4)), // 0 triangle: CL_Vec2f(center.x + offset_x , center.y + offset_y), CL_Vec2f(center.x + ((float)radius * pos2), center.y - ((float)radius * pos1)), CL_Vec2f(center.x + ((float)radius * pos4), center.y - ((float)radius * pos3)), // 270 triangle: CL_Vec2f(center.x + offset_x , center.y + offset_y), CL_Vec2f(center.x - ((float)radius * pos1), center.y - ((float)radius * pos2)), CL_Vec2f(center.x - ((float)radius * pos3), center.y - ((float)radius * pos4)), // 180 triangle: CL_Vec2f(center.x + offset_x , center.y + offset_y), CL_Vec2f(center.x - ((float)radius * pos2), center.y + ((float)radius * pos1)), CL_Vec2f(center.x - ((float)radius * pos4), center.y + ((float)radius * pos3)) }; CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, positions); prim_array.set_attributes(1, triangle_colors); gc.set_program_object(cl_program_color_only); gc.draw_primitives(cl_triangles, 4*3, prim_array); gc.reset_program_object(); } }
void App::recursive_render(CL_GraphicContext &gc, const struct aiScene *sc, const struct aiNode* nd, bool use_texture_coords) { int i; unsigned int n = 0, t; struct aiMatrix4x4 m = nd->mTransformation; // update transform aiTransposeMatrix4(&m); gc.push_modelview(); gc.mult_modelview((float*)&m); // draw all meshes assigned to this node for (; n < nd->mNumMeshes; ++n) { const struct aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]]; if (mesh->mNormals == NULL) throw CL_Exception("This example expects normals to be set"); std::vector<CL_Vec3f> normals; std::vector<CL_Vec3f> vertices; std::vector<CL_Vec3f> tex_coords; normals.reserve(mesh->mNumFaces * 3); vertices.reserve(mesh->mNumFaces * 3); if (use_texture_coords) { if (mesh->mTextureCoords == NULL || mesh->mTextureCoords[0] == NULL) throw CL_Exception("This example expects texcoords to be set for this object"); tex_coords.reserve(mesh->mNumFaces * 3); } for (t = 0; t < mesh->mNumFaces; ++t) { const struct aiFace* face = &mesh->mFaces[t]; if (face->mNumIndices != 3) throw CL_Exception("This example only supports triangles"); for(i = 0; i < face->mNumIndices; i++) { int index = face->mIndices[i]; normals.push_back(&mesh->mNormals[index].x); vertices.push_back( &mesh->mVertices[index].x); if (use_texture_coords) tex_coords.push_back( &mesh->mTextureCoords[0][index].x); } } if (!vertices.empty()) { CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(cl_attrib_position, &vertices[0]); prim_array.set_attribute(cl_attrib_color, CL_Colorf::white); prim_array.set_attributes(cl_attrib_normal, &normals[0]); if (use_texture_coords) prim_array.set_attributes(cl_attrib_texture_position, &tex_coords[0]); gc.draw_primitives(cl_triangles, vertices.size(), prim_array); } } // draw all children for (n = 0; n < nd->mNumChildren; ++n) { recursive_render(gc, sc, nd->mChildren[n], use_texture_coords); } gc.pop_modelview(); }
// The start of the Application int App::start(const std::vector<CL_String> &args) { CL_OpenGLWindowDescription win_desc; //win_desc.set_version(3, 2, false); win_desc.set_allow_resize(true); win_desc.set_title("Point Sprite Example"); win_desc.set_size(CL_Size( 800, 480 ), false); CL_DisplayWindow window(win_desc); CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up); CL_String theme; if (CL_FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css")) theme = "../../../Resources/GUIThemeAero"; else if (CL_FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css")) theme = "../../../Resources/GUIThemeBasic"; else throw CL_Exception("No themes found"); CL_GUIWindowManagerTexture wm(window); CL_GUIManager gui(wm, theme); CL_GraphicContext gc = window.get_gc(); // Deleted automatically by the GUI Options *options = new Options(gui, CL_Rect(0, 0, gc.get_size())); CL_Image image_grid(gc, "../Blend/Resources/grid.png"); CL_Texture texture_particle(gc, "Resources/particle.png"); float grid_width = (float) image_grid.get_width(); float grid_height = (float) image_grid.get_height(); grid_space = (float) (image_grid.get_width()); setup_particles(); CL_ShaderObject vertex_shader(gc, cl_shadertype_vertex, text_shader_vertex); if(!vertex_shader.compile()) { throw CL_Exception(cl_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log())); } CL_ShaderObject fragment_shader(gc, cl_shadertype_fragment, text_shader_fragment); if(!fragment_shader.compile()) { throw CL_Exception(cl_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log())); } CL_ProgramObject program_object(gc); program_object.attach(vertex_shader); program_object.attach(fragment_shader); program_object.bind_attribute_location(0, "InPosition"); program_object.bind_attribute_location(1, "InColor"); if (!program_object.link()) { throw CL_Exception(cl_format("Unable to link program object: %1", program_object.get_info_log())); } options->request_repaint(); unsigned int time_last = CL_System::get_time(); while (!quit) { unsigned int time_now = CL_System::get_time(); float time_diff = (float) (time_now - time_last); time_last = time_now; wm.process(); wm.draw_windows(gc); int num_particles = options->num_particles; if (num_particles > max_particles) num_particles = max_particles; move_particles(time_diff, num_particles); const float grid_xpos = 10.0f; const float grid_ypos = 10.0f; // Draw the grid image_grid.draw(gc, grid_xpos, grid_ypos); if (num_particles > 0) { std::vector<CL_Vec2f> positions; std::vector<CL_Vec4f> colors; positions.resize(num_particles); colors.resize(num_particles); for (int cnt=0; cnt<num_particles; cnt++) { positions[cnt] = CL_Vec2f(grid_xpos + particles[cnt].xpos, grid_ypos + particles[cnt].ypos); switch (cnt % 3) { case 0: colors[cnt] = CL_Vec4f(1.0f, 0.0f, 0.0f, 1.0f); break; case 1: colors[cnt] = CL_Vec4f(0.0f, 1.0f, 0.0f, 1.0f); break; case 2: colors[cnt] = CL_Vec4f(0.0f, 0.0f, 1.0f, 1.0f); break; } }; CL_BlendMode blend; blend.enable_blending(true); blend.set_blend_function(cl_blend_src_alpha, cl_blend_one, cl_blend_src_alpha, cl_blend_one); gc.set_blend_mode(blend); CL_Pen pen; pen.enable_point_sprite(true); pen.set_point_size(options->point_size); pen.set_point_sprite_origin(cl_point_sprite_origin_upper_left); gc.set_pen(pen); program_object.set_uniform1i("Texture0", 0); gc.set_texture(0, texture_particle); CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, &positions[0]); prim_array.set_attributes(1, &colors[0]); gc.set_program_object(program_object); gc.draw_primitives(cl_points, num_particles, prim_array); gc.reset_program_object(); gc.reset_texture(0); gc.reset_blend_mode(); gc.reset_pen(); } window.flip(1); CL_KeepAlive::process(); } return 0; }