void ContainerRenderer::checkTextureSize(CL_GraphicContext& gc) { if (texture_.is_null() || texture_.get_size() != containerView_->get_size()) { texture_ = ui::Manager::getSingleton()->providerRenderBufferTexture(containerView_->get_size()); frameBuffer_ = CL_FrameBuffer(gc); frameBuffer_.attach_color_buffer(0, texture_); } }
GraphicStore::GraphicStore(CL_GraphicContext &gc) : shader_color_geometry(gc) { // Create a depth buffer framebuffer_depth = CL_FrameBuffer(gc); texture_depth = CL_Texture(gc, gc.get_size(), cl_depth_component); texture_depth.set_wrap_mode(cl_wrap_clamp_to_edge, cl_wrap_clamp_to_edge, cl_wrap_clamp_to_edge); framebuffer_depth.attach_depth_buffer(texture_depth); // Load graphics texture_alpha_ball = CL_Texture(gc, "Resources/alpha_ball2.png"); //texture_alpha_ball = CL_Texture(gc, "Resources/alpha_ball.png"); texture_alpha_ball.set_wrap_mode(cl_wrap_clamp_to_edge, cl_wrap_clamp_to_edge, cl_wrap_clamp_to_edge); }
void ShaderImpl::initialize(CL_GraphicContext &p_gc) { G_ASSERT(!m_initialized); CL_ResourceManager *resMgr = Gfx::Stage::getResourceManager(); m_program = CL_ProgramObject(p_gc); // load vertex shader const CL_String &vertShaderName = m_parent->getVertexShaderResourceName(); m_vertShader = CL_ShaderObject::load(p_gc, vertShaderName, resMgr); m_program.attach(m_vertShader); // load fragment shader const CL_String &fragShaderName = m_parent->getFragmentShaderResourceName(); m_fragShader = CL_ShaderObject::load(p_gc, fragShaderName, resMgr); m_program.attach(m_fragShader); // bind common attributes m_program.bind_attribute_location(CL_PRIARR_VERTS, "Position"); m_program.bind_attribute_location(CL_PRIARR_COLORS, "Color0"); m_program.bind_attribute_location(CL_PRIARR_TEXCOORDS, "TexCoord0"); // link the program if (!m_program.link()) { m_program.detach(m_vertShader); m_program.detach(m_fragShader); throw CL_Exception( cl_format( "error linking shader %1, %2: %3", vertShaderName, fragShaderName, m_program.get_info_log() ) ); } // build frame buffer m_frameBuffer = CL_FrameBuffer(p_gc); // build quad m_quad = CL_PrimitivesArray(p_gc); m_quad.set_attributes(CL_PRIARR_VERTS, m_quadVerts); m_quad.set_attributes(CL_PRIARR_COLORS, QUAD_COLORS); m_quad.set_attributes(CL_PRIARR_TEXCOORDS, QUAD_TEX_COORDS); m_initialized = true; }
void ShaderImpl::destroy() { G_ASSERT(m_initialized); m_quad = CL_PrimitivesArray(); m_frameBuffer = CL_FrameBuffer(); m_program.detach(m_vertShader); m_program.detach(m_fragShader); m_vertShader = CL_ShaderObject(); m_fragShader = CL_ShaderObject(); m_program = CL_ProgramObject(); m_initialized = false; }
void CL_PixelCanvas::reset_framebuffer() { pipeline->wait_for_workers(); framebuffer_set = false; slot_framebuffer_modified = CL_Slot(); colorbuffer0.set(primary_colorbuffer0); pipeline->queue(new(pipeline.get()) CL_PixelCommandSetFrameBuffer(colorbuffer0)); framebuffer = CL_FrameBuffer(); CL_Rect rect = clip_rect; clip_rect = CL_Rect(CL_Point(0,0),colorbuffer0.size); if (cliprect_set) set_clip_rect(rect); else pipeline->queue(new(pipeline.get()) CL_PixelCommandSetClipRect(clip_rect)); }
int ExampleText::start(const std::vector<CL_String> &args) { // Create a console window for text-output if not available CL_ConsoleWindow console("Console"); quit = false; // Set a videomode CL_DisplayWindowDescription desc; desc.set_allow_resize(false); desc.set_title("ClanLib CL_SpanLayout Example"); desc.set_size(CL_Size(800, 600), true); CL_DisplayWindow window(desc); // Connect the Window close event CL_Slot slot_quit = window.sig_window_close().connect(this, &ExampleText::on_window_close); // Connect a keyboard handler to on_key_up() CL_Slot slot_keyboard_up = window.get_ic().get_keyboard().sig_key_up().connect(this, &ExampleText::on_keyboard_up); CL_GraphicContext gc = window.get_gc(); CL_TextureGroup texture_group(gc, CL_Size(512, 512)); CL_FontDescription font_desc; font_desc.set_typeface_name("Tahoma"); font_desc.set_anti_alias(true); font_desc.set_height(32); CL_Font_System font_normal(gc, font_desc); font_desc.set_weight(800); font_desc.set_height(40); CL_Font_System font_bold(gc, font_desc); // Share the font texture font_normal.set_texture_group(texture_group); font_bold.set_texture_group(texture_group); CL_Texture texture_text(gc, text_window_size, text_window_size); texture_text.set_wrap_mode(cl_wrap_repeat, cl_wrap_repeat, cl_wrap_repeat); texture_text.set_min_filter(cl_filter_linear); texture_text.set_mag_filter(cl_filter_linear); // Create the framebuffer, and attach the texture text into its color buffer CL_FrameBuffer fb_text; fb_text = CL_FrameBuffer(gc); fb_text.attach_color_buffer(0, texture_text); float angle = 0.0f; std::vector<CL_SpanLayout> layout; // Count number of lines int num_lines = 0; for (const char **text_ptr = TextToShow; *text_ptr; text_ptr++) { num_lines++; } // Extend layout vector layout.resize(num_lines); int ypos = 60; for (int line_count=0; line_count < num_lines; line_count++, ypos += 8) { layout[line_count] = CL_SpanLayout(); layout[line_count].set_position(CL_Point(20, ypos)); layout[line_count].set_align(cl_justify); const char *text_ptr = TextToShow[line_count]; if (text_ptr[0] == '-') { layout[line_count].add_text(text_ptr, font_normal, CL_Colorf::red); } else if (strstr(text_ptr, "Clan")) { layout[line_count].add_text(text_ptr, font_bold, CL_Colorf::yellow); } else { layout[line_count].add_text(text_ptr, font_normal, CL_Colorf::yellow); } layout[line_count].layout(gc, texture_text.get_width() - 60); ypos += layout[line_count].get_size().height; } // Run until someone presses escape while (!quit) { int start_time = CL_System::get_time(); gc.set_map_mode(CL_MapMode(cl_map_2d_upper_left)); // Draw a nice blue gradient in the background CL_Draw::gradient_fill(gc, window.get_viewport(), CL_Gradient(CL_Colorf::lightblue, CL_Colorf::lightblue, CL_Colorf::darkblue, CL_Colorf::darkblue)); // Draw the text into the frame buffer update_text(gc, fb_text, font_normal, layout); angle += 0.5f; if (angle >= 360.0f) angle -= 360.0f; // Draw the text draw_text(gc, texture_text, CL_Angle(angle, cl_degrees)); last_fps = 1000.0f / (CL_System::get_time()-start_time); // Flip the display, showing on the screen what we have drawn window.flip(1); // This call updates input and performs other "housekeeping" call this each frame CL_KeepAlive::process(); } return 0; }