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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:45:50+00:00 2026-05-23T02:45:50+00:00

I have a Java OpenGL (JOGL) app, and I’m trying to create a texture

  • 0

I have a Java OpenGL (JOGL) app, and I’m trying to create a texture mapped quad that covers the entire screen. In draw some pixels to a buffer and then I want to read those pixels into a texture and redraw them on screen (with a fragment shader applied). My code for mapping the texture to the viewport is:

        gl.glMatrixMode(GL.GL_PROJECTION);                                        
        gl.glPushMatrix();                                                 
        gl.glLoadIdentity();                                               
        gl.glOrtho( 0, width, height, 0, -1, 1 );                          
        gl.glMatrixMode(GL.GL_MODELVIEW);                                  
        gl.glPushMatrix();                                                 
        gl.glLoadIdentity();
        IntBuffer ib = IntBuffer.allocate(1);
        gl.glEnable(GL.GL_TEXTURE_2D);
        gl.glGenTextures(1, ib);
        gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1);
        //buff contains pixels read from glReadPixels
        gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buff);
        gl.glBindTexture(GL.GL_TEXTURE_2D, ib.get(0));
        gl.glBegin(GL.GL_QUADS);
        gl.glTexCoord2f(0,1);
        gl.glVertex2f(0,0); 
        gl.glTexCoord2f(0,0);
        gl.glVertex2f(0,height);
        gl.glTexCoord2f(1,0);   
        gl.glVertex2f(width,height);
        gl.glTexCoord2f(1,1);      
        gl.glVertex2f(width,0);
        gl.glEnd();
        gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
        gl.glPopMatrix();
        gl.glPopMatrix();

The end result is a quad that is not covering the whole viewport (it’s partially on) and that does not contain the pixels from the buffer. What am I doing incorrectly here?

thanks,
Jeff

  • 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-23T02:45:51+00:00Added an answer on May 23, 2026 at 2:45 am

    First, you should only create the texture in your initialization code. You should not be calling glTexImage2D every frame. Only call glTexImage2D again if the size of the texture changes; glTexSubImage2D can be used to upload data to the texture. Think of glTexImage2D as “new”, while glTexSubImage2D as a memory copy.

    Do this once, after initializing OpenGL.

    IntBuffer ib = IntBuffer.allocate(1);  //Store this in your object
    gl.glGenTextures(1, ib);
    gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1);
    //buff contains pixels read from glReadPixels
    gl.glBindTexture(GL.GL_TEXTURE_2D, ib.get(0));
    gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, 0);
    gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
    

    Then, each frame, do this:

    gl.glMatrixMode(GL.GL_PROJECTION);                                        
    gl.glPushMatrix();                                                 
    gl.glLoadIdentity();                                               
    gl.glMatrixMode(GL.GL_MODELVIEW);                                  
    gl.glPushMatrix();                                                 
    gl.glLoadIdentity();
    
    gl.glBindTexture(GL.GL_TEXTURE_2D, ib.get(0));  //Retrieved from your object
    gl.glEnable(GL.GL_TEXTURE_2D);
    gl.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buff);
    
    gl.glBegin(GL.GL_QUADS);
        gl.glTexCoord2f(0,1);
        gl.glVertex2f(-1, -1); 
        gl.glTexCoord2f(0, 0);
        gl.glVertex2f(-1, 1);
        gl.glTexCoord2f(1, 0);   
        gl.glVertex2f(1, 1);
        gl.glTexCoord2f(1, 1);      
        gl.glVertex2f(1, -1);
    gl.glEnd();
    
    gl.glMatrixMode(GL.GL_MODELVIEW);                                  
    gl.glPopMatrix();   
    gl.glMatrixMode(GL.GL_PROJECTION);                                        
    gl.glPopMatrix();   
    gl.glMatrixMode(GL.GL_MODELVIEW);                                  
    

    By using identity for projection and modelview, we are able to supply vertex coordinates directly in clip-space. The [-1, 1] range in clip-space maps to [0, width/height] in window space. So we don’t have to know or care about how big the window is; as long as the glViewport was set up correctly, this should work.

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

Sidebar

Related Questions

I'm trying to load an image into Java to create a texture in JoGL.
When using openGL in Java (in bindings like jogl), do you have to worry
I have Java code that works on my desk top...its a simple app that
Does Java have a built-in way to escape arbitrary text so that it can
Does Java have a data type that represents a period of time eg 34
I have a Java swing application with a panel that contains three JComboBoxe s
I have a java back-end that needs to expose services to clients running in
I have a Java application that launches another java application. The launcher has a
I'm new to OpenGL. I'm using Java/JOGL. I'm having difficulty with polygon faces. I
Always in the context of a Rubik's cube app in Java/Opengl with lwjgl, 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.