Sign in to follow this  
NEvOl

Render to texture

Recommended Posts

Hi all, I have a problem. I trying rendering to texture on GPU Intel HD 4000 by using functions floatBitsToInt and intBitsToFloat, but allways written in texture is 0. how to solve this problem?

Testing program.

write
vs.glsl
#version 400
attribute vec3 aPosition;
void main()
{
 gl_Position = vec4(aPosition.xyz, 1.0);
}
ps.glsl

void main()
{
 uint a = uint(100);
 float b = uintBitsToFloat(a);
 gl_FragColor = vec4(b, 0.0, 1.0, 1.0);

}



read
vs.glsl
#version 400
attribute vec3 aPosition;
 
varying vec2 t;
void main()
{
t = aPosition.xy;
gl_Position = vec4(aPosition.xyz, 1.0);
}


ps.glsl

uniform sampler2D texture;
varying vec2 t;
 
void main() {
float b = floatBitsToUint(texture2D(texture, t).x);
    gl_FragColor = vec4(b);
}

Share this post


Link to post
Share on other sites

I would try a couple of things

 

  • Modify ps.glsl to output a solid color to make sure it actually is drawing properly
  • Set the input texture to ps.glsl to be a texture you know isn't black to make sure you are binding the texture properly

Also, could you post the code for drawing? specifically where you create and bind the framebuffer that contains the texture you are rendering to

Share this post


Link to post
Share on other sites

all work on the nVidea GPU, but on the intel i have bugs 

creatin fbo 

    glGenTextures(1, @tex);
    glBindTexture(GL_TEXTURE_2D, tex);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, w, h, 0, GL_RGBA, GL_FLOAT, nil);
    glBindTexture(GL_TEXTURE_2D, 0);
 
    glGenFramebuffers(1, @fbo);
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
 
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
    if glCheckFramebufferStatus(GL_FRAMEBUFFER) <> GL_FRAMEBUFFER_COMPLETE then
      tex := 0;

 

rendering, plane:

  glBindFramebuffer(GL_FRAMEBUFFER, fbo);
  glClearColor(0.0, 1.0, 0.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT);
  glViewport(0, 0, Round(w), Round(h));
  glUseProgram(inProg);
 
  glBindBuffer(GL_ARRAY_BUFFER, vbo);
  glVertexAttribPointer(aPosLocIn, 3, GL_FLOAT, ByteBool(0), 0, 0);
  glEnableVertexAttribArray(aPosLocIn);
 
  glDrawArrays(GL_TRIANGLES, 0, 6);
 
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
  glClearColor(1.0, 0.0, 0.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT);
 
  glUseProgram(outProg);
 
  glBindBuffer(GL_ARRAY_BUFFER, vbo);
  glVertexAttribPointer(aPosLocOut, 3, GL_FLOAT, ByteBool(0), 0, 0);
  glEnableVertexAttribArray(aPosLocOut);
 
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, fbo);
  glUniform1i(uTexLocOut, 0);
 
  glDrawArrays(GL_TRIANGLES, 0, 6);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this