Results 1 to 4 of 4

Thread: Rendering to textures that has special size

  1. #1

    Default Rendering to textures that has special size

    Hi everyone!

    I'm writing soft 2D shadows and faced some problems.
    The main one is that when I rendering to texture I could render only to texture with size of graphic context, because of that fact I used to send additional uniforms to shaders

    Code:
    shadowcasterFB.attach_color_buffer(0, distortTexture1);
    po = shContainer->getContext("Distort");
    gc.set_program_object(*po);
    gc.set_texture(0, distanceSCMask);
    shContainer->setVariableInt("Distort", "texture", 0);
    shContainer->setVariable2F("Distort", "texSize", CL_Vec2f(lightAreaX, lightAreaY));
    gfx::draw_texture(gc, CL_Rectf(0,0,shadowSquareSize,shadowSquareSize), CL_Colorf::white, CL_Rectf(0.0, 0.0, lightAreaX, lightAreaY));
    shadowcasterFB.detach_color_buffer(0, distortTexture1);
    gc.reset_texture(0);
    gc.reset_program_object();
    so you could see that I draw in small rect in the part of texture

    Now the question: how could I make offscreen rendering to small textures with specific size depending to attached textures?
    Code:
    gfx::draw_texture(gc, CL_Rectf(0,0,1.0,1.0),CL_Colorf::white, CL_Rectf(0.0, 0.0, 1.0, 1.0));

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    when I rendering to texture I could render only to texture with size of graphic context
    You can render to textures of any size (smaller, same or larger than the graphic context)

    how could I make offscreen rendering to small textures with specific size depending to attached textures?
    It should work by default.

    Examples/Display_Text/Text does this. The GC is 800x600. The framebuffer texture is 1024x1024

    If you are working in 3D, you can use gc.set_viewport() to clip
    Code:
    	CL_Rect viewport_rect(...);
    	gc.set_viewport(viewport_rect);
    Since 3D ranges from -1.0f to 1.0f, the modelview and projection matrix should stay the same

    In 2D, if using gc.set_map_mode(cl_user_projection), you will need to set these:

    Code:
    		set_viewport(CL_Rectf(0.0f, 0.0f, width, height));
    		set_projection(CL_Mat4f::ortho_2d(0.0f, (float)width, (float)height, 0.0f));
    		set_modelview(CL_Mat4f::identity());

  3. #3

    Default

    Thanks it works for some steps
    but in the step of reduction of shadow map changing viewport to the texture size compress result in Y dimention

    the texture have sizes 2^n x gc.height

    here is the code

    Code:
    int width = shadowSquareSize;
    for (int i = texIdx - 1; i > -1; --i) {
    	width /= 2;
    	CL_Vec2f pixelSize = CL_Vec2f((1.0f / width) / 2, 1.0f / gcSize.height);
    	shContainer->setVariable2F("Reduction", "pixelSize", pixelSize);
    
    	shr.shadowsFB.attach_color_buffer(0, shr.distortTextures[i]);
    	gc.set_texture(0, shr.distortTextures[i + 1]);
    
    	setModelView(gc, width, gcSize.height);
    			
    	gfx::draw_texture(gc, CL_Rectf(0.0f,0.0f,width, shadowSquareSize), CL_Colorf::white, CL_Rectf(0.0f, 0.0f, 1.0f, lightAreaY));
    
    	shr.shadowsFB.detach_color_buffer(0, shr.distortTextures[i]);	
    	gc.reset_texture(0);
    }
    gc.reset_program_object();

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I have not done shadow maps before (I believe another developer has)

    Check the math for
    Code:
    	width /= 2;
    	CL_Vec2f pixelSize = CL_Vec2f((1.0f / width) / 2, 1.0f / gcSize.height);
    Which is the same as:
    Code:
    	CL_Vec2f pixelSize = CL_Vec2f(1.0f / width, 1.0f / gcSize.height);
    	width /= 2;
    It just looks suspicious

Similar Threads

  1. drawing on textures?
    By nemcheg in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 06-10-2010, 11:56 PM
  2. Size of CL_String
    By xenus in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 10-10-2009, 06:15 PM
  3. Textures and Memory Allocation
    By catch22 in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 05-22-2009, 10:39 PM
  4. OpenGL Textures
    By ElephantHunter in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 09-09-2008, 03:03 AM
  5. default window size...
    By harrio in forum Novashell Game Creation System
    Replies: 6
    Last Post: 02-18-2008, 05:38 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •