glDrawPixels

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Silencet
    New Member
    • Aug 2007
    • 24

    glDrawPixels

    I've been searching and reading articles and examples for the past 2 weeks, but no luck.

    Could some one please show me a good example of how to use the glDrawPixels Function to display pixels onto the screen with GL_FLOAT and GL_UNSIGNED_BYT E (using unsigned char) or just explain to me what I'm doing wrong. I've pasted my DrawScene Function Below.

    Im trying to turn the 100 pixels to red, and display them
    Code:
    int DrawScene()
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();
    	//Here i use the float setup
    	float fPixel[100][4];
    	for(int x=0; x<100;x++)
    	{
    		fPixel[x][0]=0xff;
    		fPixel[x][1]=0x00;
    		fPixel[x][2]=0x00;
    		fPixel[x][3]=0xff;
    	}
    	glDrawPixels(20, 20, GL_RGBA, GL_FLOAT, fPixel);
    	SwapBuffers(hdc);
    	return 0;
    }
    Now with GL_UNSIGNED_BYT E
    Code:
    int DrawScene()
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();
    	unsigned char pixel[100][4]
    	for(int x=0; x<100;x++)
    	{
    		pixel[x][0]=0xff;
    		pixel[x][1]=0x00;
    		pixel[x][2]=0x00;
    		pixel[x][3]=0xff;
    	}
    	glDrawPixels(20, 20, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
    	SwapBuffers(hdc);
    
    	return 0;
    }
    Neither of these work for me. Any Suggestions? Thank you
  • Silencet
    New Member
    • Aug 2007
    • 24

    #2
    ok so i figured out that it was just cuz the buffers weren't being swapped, in the Programs loop, I don't know why this is but If some one could inform me on why this must be, for worth of intellegence, that'd be great. But now i have another problem, which is glReadPixels, I continute to Get an Invalid Operation Error when i've read documentation after documentation on what could cause this, no answers seem to come.

    Im using this:
    Code:
    glReadPixels(0, 0, 640, 480, GL_RGBA, GL_UNSIGNED_BYTE, pPixels);
    With pPixels as a pointer to an unsigned character.

    I've Tried using various forms of glPixelStorei with the GL_PACK_ALIGNME NT but that doesn't seem to effect the situation at all.

    Comment

    • Silencet
      New Member
      • Aug 2007
      • 24

      #3
      Ok im not smart, I got it all figured out. The calling function "glReadPixe ls" was on a different thread than that of the Device Context, So by Using SendMessage to the Main thread to Read the Pixels into a global buffer I was able to keep processing what needed to be in the thread. BOMB oh yeah, so Just a Lesson learned on calling function using variables on seprate threads.

      Comment

      Working...