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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:41:04+00:00 2026-06-15T23:41:04+00:00

I’m working with glReadPixels for some work, and it’s behaving strangely. In particular, I

  • 0

I’m working with glReadPixels for some work, and it’s behaving strangely. In particular, I run the following test:

unsigned char pixels[ 512 * 512 * 4 ];

int mid = 0;
while (mid < 512) {
  printf("Test %d : ", mid);
  memset(pixels, 0, 512*512*4);
  pixels[1] = 0x42;
  glReadPixels( 0, 0, mid, 511, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
  printf(" %x ", pixels[1]);
  if (pixels[0] == 0) {
    printf("0\n");
  } else {
    printf("1\n");
  }
  mid++;
}

With output:

Test 0 :  42 0
Test 1 :  67 1
Test 2 :  67 1
Test 3 :  67 1
Test 4 :  42 0
Test 5 :  67 1
Test 6 :  67 1
Test 7 :  67 1
Test 8 :  42 0
Test 9 :  67 1
Test 10 :  67 1
Test 11 :  67 1

I have already drawn data to the entire screen (the 0x67 is the correct byte for the color I’m drawing) so I’m not sure what’s going on here.

The main thing I actually want is to get a copy of every pixel currently on the screen inside of an array I can access not on the GPU. I’m not sure if this is the ‘correct’ way about getting it, but it’s the only way I know of. Is there a better way of doing this?

  • 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-15T23:41:05+00:00Added an answer on June 15, 2026 at 11:41 pm

    You could use this code to first create an empty texture (use it just once, before your update loop):

    GLuint texID;
    
    GLubyte *data = (GLubyte*)malloc(width*height*4*sizeof(GLubyte));
    ZeroMemory(data,width*height*4*sizeof(GLubyte));
    
    glGenTextures(1, (GLuint*)texID);
    glBindTexture(GL_TEXTURE_2D, texID);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
    

    Then use the following to copy the current buffer to your texture (use this at the end of every update loop, just before you swap buffers):

    glBindTexture(GL_TEXTURE_2D,texID);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, width, height, 0);
    

    And finally use this to retrieve an array with RGBA pixel data (right after the previous bit):

    GLubyte *pixels = (GLubyte*)malloc(width*height*4*sizeof(GLubyte));
    glBindTexture(GL_TEXTURE_2D,texID);
    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
    

    It all depends on what you want to do with this pixel data ofcourse. This may not help you at all, but I hope it will ;).

    • 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 have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.