Advertisement

02.11.2005 at 02:18AM PST, ID: 21310907
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

A simple question on how to use glReadPixels()

Tags: glreadpixels
Hi,

I'm a newbie in OpenGL so hope someone can really help!

I have written a short program to draw a magenta square. It occupies a pixel area. I then attempted to read the color buffer to see how it works, but it gave me values that do not correspond to magenta's RGB code (ie. 1,0,1).
Can anyone explain where I went wrong?

/***** My Program ******/

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

void init(void)
{
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel (GL_FLAT);
}


void display(void)
{
   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glEnable (GL_DEPTH_TEST);
   glColor3f (1.0, 1.0, 1.0);
   glLoadIdentity (); /* clear the matrix to the identity matrix */
   
   glColor3f(1.0, 0.0, 1.0);       //set color to be magenta.
   int p1 [] = {0, 0};          //using array.
   int p2 [] = {1, 0};
   int p3 [] = {1, 1};
   int p4 [] = {0, 1};

   glBegin (GL_QUADS);
      glVertex2iv(p1);         //specify point positions.
      glVertex2iv(p2);
      glVertex2iv(p3);
      glVertex2iv(p4);
   glEnd ();
 
   /* read color buffer */
   int width=2, height=2;
   float pixels [3*width*height];
   glReadBuffer(GL_FRONT_LEFT);
   glReadPixels(-1,-1,width,height,GL_RGB,GL_FLOAT,pixels);
   std::cout << "----" << std::endl;
   for (int i=0; i<3*width*height; i++){
       std::cout << pixels[i] << std::endl;
   }
   
   glDisable (GL_DEPTH_TEST);
   glFlush ();
}


void reshape (int w, int h)
{
   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode (GL_MODELVIEW);   /* current matrix specifies the model matrix */
}


int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
   glutInitWindowSize (500, 500);
   glutInitWindowPosition (100, 100);
   glutCreateWindow (argv[0]);
   init ();
   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutMainLoop();
   return 0;
}


/****** My Results Obtained from MinGW command prompt *******/
1.26117e-044
3.20173e-039
3.21383e-039
1.04836e-033
0
1
3.2031e-039
1.#QNAN
3.20173e-039
0
0
0



thanks,
- capricious
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: capricious
Solution Provided By: davebytes
Participating Experts: 3
Solution Grade: B
Views: 100
Translate:
Loading Advertisement...
02.11.2005 at 07:44AM PST, ID: 13286759

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.11.2005 at 08:20AM PST, ID: 13287208

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.11.2005 at 01:46PM PST, ID: 13290477

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.11.2005 at 01:49PM PST, ID: 13290538

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.11.2005 at 10:43PM PST, ID: 13292663

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.12.2005 at 07:11AM PST, ID: 13293827

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.12.2005 at 02:42PM PST, ID: 13295541

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2005 at 03:31AM PST, ID: 13381016

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2005 at 03:35AM PST, ID: 13381037

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29