Go Back   nV News Forums > Linux Support Forums > NVIDIA Linux

Newegg Daily Deals

Reply
 
Thread Tools
Old 12-14-04, 05:54 AM   #1
Yesmad
Registered User
 
Join Date: Dec 2004
Posts: 2
Question Nvidia drivers and glReadPixels

Hello,

I have a strange problem with the nvidia-drivers (and SuSE 9.1) and glReadPixels. The following code creates a 512x512 window and clears it with (.1,.2,.3,0.0), so the alpha value should be 0.0 over the whole window. But, when I (by pressing a key) read out the alpha buffer, then only 1.0's are printed. I tested the code with mesa rendering only, and then the output is correct. What am I doing wrong, or is there a problem with the driver?

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <iostream>
#include <iomanip>

unsigned int width = 512;
unsigned int height = 512;

void keyboard(unsigned char key, int x, int y)
{
GLubyte the_image[height][width];
glFlush();
glReadPixels(0,0,width, height, GL_ALPHA, GL_UNSIGNED_BYTE, the_image);
for (int i=0; i<width; i++) {
for (int j=0; j<height; j++) {
std::cout << the_image[j][i] << " ";
}
}
}

void display(void)
{
glEnable(GL_BLEND);
glClearColor(.1,.2,.3,0.0);
glClear(GL_COLOR_BUFFER_BIT);

glFlush();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_RGBA | GLUT_DEPTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glutInitWindowSize(width,height);
glutCreateWindow("test");

glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();

return 0;
}
Yesmad is offline   Reply With Quote
Old 12-14-04, 09:53 AM   #2
tpurtell
Registered User
 
Join Date: Dec 2004
Posts: 6
Default Re: Nvidia drivers and glReadPixels

GLUT's implementation is to blame for this.

GLUT_RGB and GLUT_RGBA are actually the same thing.

They simply indicate that you are rendering in a true-color (vs indexed) rendering mode.

To get an alpha buffer with GLUT you need to pass GLUT_ALPHA into the display mode function.

glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA);

That should fix it.
tpurtell is offline   Reply With Quote
Old 12-14-04, 10:50 AM   #3
Yesmad
Registered User
 
Join Date: Dec 2004
Posts: 2
Default Re: Nvidia drivers and glReadPixels

Yes you are right...I just found it myself before I got your mail.

Thanks
Yesmad is offline   Reply With Quote
Old 12-14-04, 05:35 PM   #4
vincoof
Registered User
 
Join Date: Sep 2004
Location: France
Posts: 104
Send a message via ICQ to vincoof Send a message via AIM to vincoof
Default Re: Nvidia drivers and glReadPixels

If you ever want to check the number of bytes your alpha channel really has, call glGetInteger(GL_ALPHA_BITS, &alpha_bits); once the rendering context is created.
I guess you would have seen immediately the problem then.
vincoof is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:17 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.