PDA

View Full Version : Issue combining tutorials.



Casey Abernathey
03-17-2013, 05:53 PM
First let me say hello. First time posting on the forum. I am just beginning to experiment with clanlib and I have a little issue that I hope someone could help me to better understand what is going on with the frame buffers from the CanvasAdvanced tutorial. Maybe even provide a solution. See the issue below.

I am trying to combine the CanvasAdvanced and RTSGame tutorials to add a "fog of war" effect. However, my sprites all seem to have some sort of affect applied to them. See the picture below.

2310


void World::draw()
{
// Draw background
CL_Rect window_rect = window.get_viewport();
gc.set_texture(0, background);
CL_Draw::texture(gc, window_rect);
gc.reset_texture(0);

// Draw all gameobjects
{
std::list<GameObject *>::iterator it;
for(it = objects.begin(); it != objects.end(); ++it)
(*it)->draw();
}

// Draw fog of war clipping areas, everything before this will be affected by the fog of war.
lights.update(1);
// Set the working framebuffer
gc.set_frame_buffer(fb_lightmask);

// Clear it from last frame.
// -- Here is where day/night can be accomplished, but interpolating the color/alpha values.
gc.clear(CL_Colorf(0.0f,0.0f,0.0f,1.0f));

// Draw the Light cutouts
lights.draw_clips(gc);

// We're done making our changes to the texture, so reset the buffer.
gc.reset_frame_buffer();

// Draw the lightmask texture
// The color of the texture here can influence your output. I chose to keep it simple
// by staying white with 100% alpha.
gc.set_texture(0, light_mask);
gc.mult_scale(CANVAS_SCALE_X,CANVAS_SCALE_Y);
CL_Draw::texture(gc, CL_Rect(light_mask.get_size()), CL_Colorf(.8f, .8f, .8f, .4f));
gc.pop_modelview();

// Reset
gc.reset_texture(0);

// Draw drag area
if(dragging)
{
float s = (sinf(CL_System::get_time() / 200.0f) + 3.0f) / 4.0f;


CL_Draw::box(gc,
CL_Rectf(dragArea.left - 1, dragArea.top - 1, dragArea.right + 1, dragArea.bottom + 1),
CL_Colorf(0.0f, 1.0f, 0.0f, (100.0f * s)/256.0f));
CL_Draw::box(gc,
CL_Rectf(dragArea.left, dragArea.top, dragArea.right, dragArea.bottom),
CL_Colorf(0.0f, 1.0f, 0.0f, (200.0f * s)/256.0f));
CL_Draw::box(gc,
CL_Rectf(dragArea.left + 1, dragArea.top + 1, dragArea.right - 1, dragArea.bottom - 1),
CL_Colorf(0.0f, 1.0f, 0.0f, (100.0f * s)/256.0f));
}
}

rombust
03-18-2013, 08:41 AM
Try using the clanGL target, not clanGL1.

clanGL1 does not handle framebuffers correctly when using blend modes.

Casey Abernathey
03-18-2013, 01:46 PM
Try using the clanGL target, not clanGL1.

clanGL1 does not handle framebuffers correctly when using blend modes.

Awesome! Changing to USE_OPENGL_2 fixed the issue. Thanks!