Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6652863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:11:41+00:00 2026-05-26T01:11:41+00:00

I’m having trouble implementing render to texture with OpenGL 3. My issue is that

  • 0

I’m having trouble implementing render to texture with OpenGL 3.

My issue is that after rendering to the frame buffer, it appears the rendered object becomes deformed, which may imply a bad transformation has occurred somewhere. Which doesn’t make sense as the object renders fine when not using my frame buffer (see bottom of post).

The current result is such:

Current result http://k.minus.com/jZVgUuLYRtapv.jpg

And the expected result was this (or something similar, this has just been GIMP’d):
Expected http://k.minus.com/jA5rLM8lmXQYL.jpg

It therefore implies that I’m doing something wrong in my frame buffer set up code, or elsewhere. But I can’t see what.


The FBO is set up through the following function:

unsigned int fbo_id;
unsigned int depth_buffer;
int m_FBOWidth, m_FBOHeight;
unsigned int m_TextureID;

void initFBO() {
    m_FBOWidth = screen_width;
    m_FBOHeight = screen_height;

    glGenRenderbuffers(1, &depth_buffer);
    glBindRenderbuffer(GL_RENDERBUFFER, depth_buffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_FBOWidth, m_FBOHeight);

    glGenTextures(1, &m_TextureID);
    glBindTexture(GL_TEXTURE_2D, m_TextureID);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    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_RGBA8, m_FBOWidth, m_FBOHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glBindTexture(GL_TEXTURE_2D, 0);

    glGenFramebuffers(1, &fbo_id);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_id);

    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_buffer);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TextureID, 0);

    assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

Here is my drawing box code, which just takes a transformation matrix and calls the appropriate functions. The current values of P is a projection matrix, and an identity matrix for the view matrix (V).

void drawBox(const Matrix4& M) {
    const Matrix4 MVP = M * V * P;

    if (boundshader) {
        glUniformMatrix4fv((*boundshader)("MVP"), 1, GL_FALSE, &MVP[0]);
    }

    glBindVertexArray(vaoID);
    glDrawElements(GL_TRIANGLES, sizeof(cube.polygon)/sizeof(cube.polygon[0]), GL_UNSIGNED_INT, 0);
}

void drawStaticBox() {
    Matrix4 M(1);
    translate(M, Vector3(0,0,-50));

    drawBox(M);
}

void drawRotatingBox() {
    Matrix4 M(1);
    rotate(M, rotation(Vector3(1, 0, 0), rotation_x));
    rotate(M, rotation(Vector3(0, 1, 0), rotation_y));
    rotate(M, rotation(Vector3(0, 0, 1), rotation_z));
    translate(M, Vector3(0,0,-50));

    drawBox(M);
}

And the display function called by GLUT.

void OnRender() {
    /////////////////////////////////////////
    // Render to FBO

    glClearColor(0, 0, 0.2f,0);

    glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
    glViewport(0, 0, m_FBOWidth, m_FBOHeight);
    glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
    GL_CHECK_ERRORS

    colorshader.Use();
    boundshader = &colorshader;

    drawRotatingBox();

    colorshader.UnUse();

    /////////////////////////////////////////
    // Render to Window

    glClearColor(0, 0, 0, 0);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glViewport(0, 0, screen_width, screen_height);
    glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
    GL_CHECK_ERRORS

    texshader.Use();
    boundshader = &texshader;

    glBindTexture(GL_TEXTURE_2D, m_TextureID);
    drawStaticBox();

    texshader.UnUse();

    // Swap le buffers
    glutSwapBuffers();
}

And… the obligatory texture shader code

vertex

#version 330

in vec2 vUV;
in vec3 vVertex;
smooth out vec2 vTexCoord;

uniform mat4 MVP;
void main()
{
   vTexCoord = vUV;
   gl_Position = MVP*vec4(vVertex,1);
}

fragment

#version 330
smooth in vec2 vTexCoord;
out vec4 vFragColor;

uniform sampler2D textureMap;

void main(void)
{
   vFragColor = texture(textureMap, vTexCoord);
}

The following is what is rendered when not using the FBO logic:
What is rendered to the FBO http://k.minus.com/jiP7kTOSLLvHk.jpg


… Help?

Any ideas on what I may be doing wrong?
Further source available on request.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:11:42+00:00Added an answer on May 26, 2026 at 1:11 am

    As was pointed out by Jari Komppa on GameDev.stackexchange, and neodelphi as a comment on my main post.

    The texture coordinates were wrong (or in my case, not passed).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.