Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: Render to Texture / Uniform Texture problem

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2013
    Posts
    4

    Render to Texture / Uniform Texture problem

    Hello everyone.
    This is what I'm trying to do: I want to render somethign to texture in framebuffer, then use this texture asi uniform for another set of shaders, and they use texture's values to compute something. I've tried disabling rendering to special framebuffer, so it renders directly to screen and I see output there. So I can assume when I render to special framebuffer, texture is filled. However, when I try to acces this texture in second sets of shaders, texture2D(..) always returns black color. Here's code:
    Code :
                // create texture
               glGenTextures(1, &texA);
    	glBindTexture(GL_TEXTURE_2D, texA);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA,GL_UNSIGNED_BYTE, NULL);
               // create framebuffer
               glGenFramebuffers(1, &fbA);
    	glBindFramebuffer(GL_FRAMEBUFFER, fbA);
    	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texA, 0);
               // render to framebuffer
               glViewport(0, 0, 32, 32);
               glBindFramebuffer(GL_FRAMEBUFFER, fbA);
    	glEnableVertexAttribArray(vertexPosition3DLogic);
    	glBindBuffer(GL_ARRAY_BUFFER, LBO);
    	glVertexAttribPointer(vertexPosition3DLogic, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), NULL);
    	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // output to screen is ok
    	glDisableVertexAttribArray(vertexPosition3DLogic);
     
    	glViewport(0, 0, 1024, 600);
    	glBindFramebuffer(GL_FRAMEBUFFER, 0);
     
               // render to screen
               glActiveTexture(GL_TEXTURE0);
    	glBindTexture(GL_TEXTURE_2D,texA);
               glUniform1i(inputTextureLocation, 0);
    	//Enable vertex position
    	glEnableVertexAttribArray(vertexPosition3D);
    	//Set vertex data
    	glBindBuffer( GL_ARRAY_BUFFER, VBO );
    	glVertexAttribPointer(vertexPosition3D, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), NULL);
    	glEnableVertexAttribArray(vertexNormal);
    	glBindBuffer( GL_ARRAY_BUFFER, NBO );
    	glVertexAttribPointer(vertexNormal, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), NULL);
     
    	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
    	glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, NULL );

    Can anyone please tell me what's wrong? Thank you very much.

    EDIT: I didn't show useProgram(), this happens between rendering to framebuffer and rendering to screen but I'm 100% sure it's correct.
    EDIT2: It's actually kinda working: When I run it, my object flashes with color from texture and then color changes permanently to completely transparent.
    Last edited by EdKeens; 09-29-2013 at 04:43 AM.

Posting Permissions

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