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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:17:00+00:00 2026-05-23T08:17:00+00:00

I hope that this ends up being a simple question. I’m using JOGL in

  • 0

I hope that this ends up being a simple question.

I’m using JOGL in Netbeans to create a checkerboard of pixels where you can specify the number of tiles in each row/col, and also the color of each of these tiles (draw this tile with 0 alpha, draw that tile with full alpha). Speed is not an issue, nor is efficiency.

Here’s my problem: When I attempt to use glDrawPixels() my glCanvas is sparsely filled rather then completely filled. As you can see I’m currently trying to get a simple case of the drawing working before moving on to the more involved stuff. I’m filling a 1D byte array with the value of a filled byte. Next I give this to glDrawPixels() to write to the color buffer.

Am I handling the byte array incorrectly? In practice (as opposed to several tutorials I’ve seen) the method only takes a form of a Buffer for the actual data, so that’s why I’ve wrapped up the byte array.

Also, the method seems to expect twice the data than the dimensions you specify to it. For instance you can see here that although I’m telling it to manage an area of width by height, it throws an exception unless the byte array is actually double the width by double the height.

I’m using glDrawPixels() because I’ve read that it’s the correct way to manage pixels.

        byte[] src = new byte[(width*2)*(height*2)];

        for(int a=0; a<height*2; a++){
            for(int b=0; b<width*2; b++){
                src[a*b+b]= 127;
            }
        }

        gl.glDrawPixels(width, height,
                GL.GL_RED, GL.GL_UNSIGNED_BYTE,
                ByteBuffer.wrap(src));

Note that width and height are the dimensions of my canvas(256×256), so this operation should take up the entire canvas’s area.

I’d really appreciate any help you can give me. I’m fine with solutions that involve completely different approaches (as long as they still mean using JOGL). That being said I’d rather not do this in a fragment shader. Thanks for your time.

  • 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-23T08:17:01+00:00Added an answer on May 23, 2026 at 8:17 am

    Your buffer layout is wrong. A image of n×m pixels and k bytes per pixel has n*m*k elements. And to access the buffer you have to advance width*y + x elements. Any buffer overruns despite correct buffer size and parameters passed is due to wrong pixel unpack settings.

    So change it to this:

    byte[] src = new byte[width*height];
    
        for(int a=0; a<height; a++){
            for(int b=0; b<width; b++){
                src[a*width+b]= 127;
            }
        }
    
        gl.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        gl.glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
        gl.glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
    
        gl.glDrawPixels(width, height,
                GL.GL_RED, GL.GL_UNSIGNED_BYTE,
                ByteBuffer.wrap(src));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I downloaded these zip files from the link http://netbeans.org/downloads/zip.html with the hope that this
This really, really urks me, so I hope that someone can give me a
This is a very strange problem, and I just hope that I can clearly
I hope I can explain this well enough so that you can understand the
I hope I can explain this right I have two input fields that require
I hope that this one is not going to be ask-and-answer question... here goes:
I hope that this is a quick question to answer. I am developing a
I hope that this question hasn't been asked already, but I was looking for
this question can create a misunderstanding: I know I have to use CSS to
I hope that someone can help me with this problem that I've been having

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.