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 7020613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:20:27+00:00 2026-05-27T23:20:27+00:00

I’m tyring to get rendering to texture working, but am having a bit of

  • 0

I’m tyring to get rendering to texture working, but am having a bit of trouble. I’m trying to render a simple quad to the screen to make sure everything is working.

    target->enable();

    glBegin(GL_QUADS);

    glColor4f(1.f, 0.f, 0.f, 1.f);
    glVertex3f(0.f, 0.f, 0.f);

    glColor4f(0.f, 1.f, 0.f, 1.f);
    glVertex3f(16.f, 0.f, 0.f);

    glColor4f(0.f, 0.f, 1.f, 1.f);
    glVertex3f(0.f, 16.f, 0.f);

    glColor4f(1.f, 1.f, 0.f, 1.f);
    glVertex3f(16.f, 16.f, 0.f);

    glEnd();

    target->disable();

When I draw the quad to the screen normally, the quad renders as expected. However, when I draw the quad with the render target enabled, the quad gets rendered at the bottom left corner of the screen and ends up not being rendered to the target.

RenderTarget::RenderTarget(GraphicsDevice *graphics, GLuint width, GLuint height) {

    mWidth = width;
    mHeight = height;

    // First create the depth buffer
    glGenRenderbuffers(1, &mDepth);
    glBindRenderbuffer(GL_RENDERBUFFER_EXT, mDepth);

    // Tell OpenGL that this renderbuffer is going to be a depth buffer
    glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, mWidth, mHeight);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mDepth);

    glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);

    // Create the frame buffer texture
    glGenTextures(1, &mTexture);
    glBindTexture(GL_TEXTURE_2D, mTexture);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    glBindTexture(GL_TEXTURE_2D, 0);

    // Create the frame buffer
    glGenFramebuffers(1, &mFbo);
    glBindFramebuffer(GL_FRAMEBUFFER_EXT, mFbo);

    // Attach the texture
    glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, mTexture, 0);

    //Attach the depth buffer
    glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mFbo);

    glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);


}

RenderTarget::~RenderTarget() {
    glDeleteBuffers(1, &mFbo);
    glDeleteBuffers(1, &mDepth);
    glDeleteTextures(1, &mTexture);
    mFbo = 0;
    mDepth = 0;
    mTexture = 0;
}

void RenderTarget::enable() {
    // Bind the frame buffer
    glBindFramebuffer(GL_FRAMEBUFFER_EXT, mFbo);
    // store the glViewport and glEnable states
    //glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);

    glClearColor(1.f, 0.f, 0.f, 1.f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glClearColor(0.f, 0.f, 0.f, 0.f);

    glLoadIdentity();
}

void RenderTarget::disable() {
    // Restore glViewport and glEnable states
    glPopAttrib();
    glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
}
  • 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-27T23:20:28+00:00Added an answer on May 27, 2026 at 11:20 pm

    Your enable is resetting the current matrix (most likely modelview) with glLoadIdentity. This explains why your square is being moved to the corner of the screen.

    You’ve commented out the call to glPushAttrib but not the matching call to glPopAttrib. If you don’t use glPushAttrib anywhere else this should set an error flag and leave GL state alone, but I don’t know that’s the case and it’s asking for trouble to assume that the attribute stack is and always will be empty.

    This documentation for glBindFrameBuffer suggests that you ought to be using GL_FRAMEBUFFER or GL_DRAW_FRAMEBUFFER as the first argument:

    target must be either GL_DRAW_FRAMEBUFFER, GL_READ_FRAMEBUFFER or
    GL_FRAMEBUFFER. If a framebuffer object is bound to
    GL_DRAW_FRAMEBUFFER or GL_READ_FRAMEBUFFER, it becomes the target for
    rendering or readback operations, respectively, until it is deleted or
    another framebuffer is bound to the corresponding bind point. Calling
    glBindFramebuffer with target set to GL_FRAMEBUFFER binds framebuffer
    to both the read and draw framebuffer targets.

    The enums with _EXT suffix in your code likely pertain to a version of OpenGL previous to the version documented there. Tutorials are prone to allowing details like this to fall out of date.

    Check your environment & rely on the documentation that matches your version of OpenGL. If for some reason you can’t easily determine your version of OpenGL, check for the GL_INVALID_ENUM error after calling glBindFrameBuffer.

    • 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
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to render a haml file in a javascript response like so:
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.