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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:07:05+00:00 2026-06-04T19:07:05+00:00

I want to be able to render something into a texture, on OpenGL, so

  • 0

I want to be able to render something into a texture, on OpenGL, so I can further use it whenever I want, without rendering everything over again. This website here gave me the guidelines to do it, without using the FrameBuffer. I don’t want to do it with the FrameBuffer Object due to compatibility issues, since this old machine is not supporting it. I have done some code, which creates my texture, renders my scene, and I then create a Quad to render the texture on it. The only problem is that the texture is being rendered like an “Alpha Mask”, it means, looks like it’s only taking into account the Alpha Value, maintaining my rectangle always with the same color, but just changing the transparency on pixels. Here is some code I’ve done so far:

void CreateTexture ()
{
    xSize = 512;
    ySize = 512; //size of texture
//new array
    char* colorBits = new char[ xSize * ySize * 3 ];
//texture creation..
    glGenTextures(1,&texture);
    glBindTexture(GL_TEXTURE_2D,texture);
    glTexImage2D(GL_TEXTURE_2D,0 ,3 , xSize,
                 ySize, 0 , GL_RGB,
                 GL_UNSIGNED_BYTE, colorBits);
//you can set other texture parameters if you want
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//clean up
    delete[] colorBits;
}

Then:

int viewport[4];
    glGetIntegerv(GL_VIEWPORT,(int*)viewport);
    glViewport(0,0,xSize,ySize);


    DrawScene(hDC);

    //save data to texture using glCopyTexImage2D
    glBindTexture(GL_TEXTURE_2D,texture);

    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
                     0,0, xSize, ySize, 0);
    glClearColor(.0f, 0.5f, 0.5f, 1.0f);                // Set The Clear Color To Medium Blue
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
    // glBindTexture(GL_TEXTURE_2D,texture);

And Finally:

glEnable(GL_TEXTURE_2D);                    // Enable 2D Texture Mapping
        glBlendFunc(GL_DST_COLOR,GL_ONE);               // Set Blending Mode
        glEnable(GL_BLEND);

        glClear(GL_COLOR_BUFFER_BIT);
        glBindTexture(GL_TEXTURE_2D,texture);

        glRotatef(theta, 0.0f, 0.0f, 0.01f);
        glBegin(GL_QUADS);
         //Front Face
        glTexCoord2f(0.0f, 0.0f);
        glVertex3f(-0.5, -0.5f,  0.5f);
        glTexCoord2f(1.0f, 0.0f);
        glVertex3f( 0.5f, -0.5f,  0.5f);
        glTexCoord2f(1.0f, 1.0f);
        glVertex3f( 0.5f,  0.5f,  0.5f);
        glTexCoord2f(0.0f, 1.0f);
        glVertex3f(-0.5f,  0.5f,  0.5f);
        glEnd();
        SwapBuffers(hDC);

The DrawScene() function simply renders a rectangle with a triangle on top of it, with each vertice having different colors.. nothing special.

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT );//| GL_DEPTH_BUFFER_BIT);

glPushMatrix();
//    glRotatef(theta, 0.0f, 0.0f, 1.0f);

glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f,  1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f,  1.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f( 1.0f,  1.0f,  1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f,  1.0f,  1.0f);
glEnd();

glBegin(GL_TRIANGLES);

glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(0.0f,   1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(0.87f,  -0.5f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(-0.87f, -0.5f);
glEnd();
glPopMatrix();
  • 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-06-04T19:07:06+00:00Added an answer on June 4, 2026 at 7:07 pm

    I’ve found something on nVidia website which looks useful, for someone who cannot also do offscreen rendering with FBO:

    http://developer.download.nvidia.com/SDK/9.5/Samples/samples.html

    This website contains one project called “Simple P-Buffer”, which basically contains an implementation of a P-buffer. The idea of the sample is that you make context switching to the pBuffer, while you want to draw pixels on offscreen mode, let’s say. After drawing your scene with the normal rendering functions, we use glReadPixels to read the data from the pBuffer into an array of unsigned bytes (GLubyte). After that, we do context-switching once again, setting it back to the screen context, so that you can use glReadPixels to read the content from our array.

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

Sidebar

Related Questions

I want to be able to render a Grid while the number of some
i want to be able to take html code and render plain text out
I want to be able to open my website and use some kind of
I want to be able to use mklink to create symbolic links on my
I am making a responsive website and I want to be able to use
How can I use a custom control to render other controls? Obviously, at the
I want to be able to do something like this: <uc:MyUC> <CustomContent> <span id=name>johnny
I'm using LaTeX and BibTeX for an article, and I want to able to
Want to be able to provide a search interface for a collection of objects
I want to be able to email a report daily from a glpi database

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.