Results 1 to 4 of 4

Thread: Render to texture

  1. #1
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default Render to texture

    Hello, so I have such code:

    Code:
            // Required objects ---------------------------
            CL_Texture mOffscreenTexture;
            CL_FrameBuffer mOffscreenBuffer;
    
            CL_ProgramObject mShader;
    
            mOffscreenTexture = CL_Texture(mGC, mGC.get_width(), mGC.get_height());
            mOffscreenBuffer = CL_FrameBuffer(mGC);
            mOffscreenBuffer.attach_color_buffer(0, mOffscreenTexture);
    
            mShader = CL_ProgramObject::load(mGC, "media/v.glsl", "media/f.glsl");
            mShader.bind_attribute_location(0, "Position");
            mShader.bind_attribute_location(1, "Color0");
            mShader.bind_attribute_location(2, "TexCoord0");
            if (!mShader.link()) std::cout << "Failed to compile shader!\n";
    
            // Application update cycle -------------------
            mGC.set_frame_buffer(mOffscreenBuffer);
            // DRAW MY OBJECTS IN CYCLE
            mGC.reset_frame_buffer();
    
    
            mGC.set_texture(0, mOffscreenTexture);
    
            mGC.set_program_object(mShader, cl_program_matrix_modelview_projection);
            draw_texture(mGC, CL_Rect(0, 0, mGC.get_width(), mGC.get_height()), CL_Colorf::white, CL_Rectf(0, 0, 1, 1));
            mGC.reset_program_object();
    
            mGC.reset_texture(0);
    draw_texture function is taken from ClanLib examples with shaders. So, this way everything is cool. My objects are drawen into my own CL_Texture and then it's displayed at main screen.

    Now the problem: I want to modify with shader in some object my CL_Texture. In other words, take my active texture and modify it somehow. Here is the code of some object update function:

    Code:
            CL_Texture curTexture = GetRenderedTexture(); // Returns my mOffscreenTexture
    
            //gc.set_texture(0, curTexture);
    
            # cl_program_matrix_modelview_projection = 0x1
            gc.set_program_object(mShaderObject, 0x1);
    
            draw_texture(gc, CL_Rectf(0, 0, ScreenResolutionX, ScreenResolutionY), CL_Colorf::white, CL_Rectf(0, 0, 1, 1));
    
            gc.reset_program_object()
            // gc.reset_texture(0);
    But that code in update cycle doesn't change the CL_Texture. In shader I just fill all pixels with red color.
    What's wrong?

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

    Default

    You have commented out " //gc.set_texture(0, curTexture);" ??

  3. #3
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    Quote Originally Posted by rombust View Post
    You have commented out " //gc.set_texture(0, curTexture);" ??
    It doesn't work without commenting too.

  4. #4
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    Okay, my fault.
    I can't use:
    Code:
    //cl_program_matrix_modelview_projection = 0x1
    gc.set_program_object(mShaderObject, 0x1);
    This way, so strange, but only direct `cl_program_matrix_modelview_projection` works.

Similar Threads

  1. Software render fail
    By Ockonal in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 12-24-2010, 10:32 PM
  2. Multipass render and alpha
    By Ockonal in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 10-08-2010, 10:20 AM
  3. New Texture 3D example
    By rombust in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 11-24-2009, 02:12 PM
  4. ClanLib 2.0 & MRT (Multi-Render-Targets)
    By wizardofoz in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 06-01-2009, 04:38 PM
  5. Render Targets
    By ShadowDust in forum Novashell Game Creation System
    Replies: 0
    Last Post: 12-21-2008, 08:13 AM

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
  •