Jump to content

  • Log In with Google      Sign In   
  • Create Account


Displaying a .pgm file with OpenGL and GLUT


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Jek Hawkins   Members   -  Reputation: 122

Like
0Likes
Like

Posted 26 January 2009 - 03:47 PM

I've been all over the internet and this website for numerous hours looking for some hint as to what is going wrong with this, to no avail. I am trying to display an ASCII .pgm file (code P2) with OpenGL and the GLUT library. The following code is only a piece of the full code, and is called by the glutDisplayFunc(). I'd greatly appreciate it if someone could tell me what it is I am doing wrong and give me a hint on how to fix it. Currently the program either crashes or displays gobbledygook, with no discernible pattern.

With all the searching and experimentation I've done over the past few days, I am fairly certain it is a problem glDrawPixels() and how I am handing the pixel array into said function.

Thanks in advance,

void displayPGM()
{
ifstream display;
char nextline[500];
int* pixeldata;
int height = 0;
int width = 0;

display.open(outname.c_str());

while(display.peek() < '0' || display.peek() > '9')
display.getline(nextline, 500);

display >> height >> width;

display.getline(nextline, 1000);

pixeldata = new int[height*width];

for(int i = 0; i < height*width; i++)
display >> pixeldata[i];

glClear(GL_COLOR_BUFFER_BIT);
glDrawPixels(width, height, GL_LUMINANCE, GL_INT, &pixeldata);
glFlush();
}

Sponsor:

#2 songho   Members   -  Reputation: 268

Like
0Likes
Like

Posted 27 January 2009 - 06:26 AM

I believe PGM is 8-bit grayscale image format, therefore the data type in glDrawPixels() would be GL_UNSIGNED_BYTE instead of GL_INT.

You may have other mistakes on loading the pixmap and OpenGL codes. Please refer to the following codes. It includes a C++ PGM (P2 and P5) loader/writer class and OpenGL (GLUT) codes to draw the PGM image to the screen;

imagePgm.zip
imagePpm.zip





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS