View Full Version : glDrawPixels and data "stretching"

02-10-2011, 04:22 PM
Ok-I give up. I've been combing the web for weeks and have read most of the redbook and a lot of the blue book and have downloaded lots of example code, but I still haven't found the answer to my problem. Keep in mind I am a newbie when it comes to OpenGL. I am rewriting my old legacy code which takes real time radar data and draws it to the screen. My legacy code was written using xView and Xlib. The piece of that code that I am working on takes a beam and displays it on the right hand side of the window. The y axis is range and the x axis is beam number, so this is only a two dimensional image. As each new beam comes in on the right hand side, the older beams move over one pixel to the left. I have rgba data for every pixel in the xy plane. What I am seeing is that when the data is first displayed the 500 pixels are not my 500 pixels but are the first 10 (or so) range values stretched out. As each new beam comes in more ranges are displayed. My 500 pixels in the y direction are never all displayed (although over 300 of them are by the time I get to the left hand side of the window). Once the window is filled, the new beams start on the right hand side again and the 3 or so ranges will take up about 25% of the 500 pixels (duplicated by openGL) and then the data will compact slowly again with each new beam. (I am on a linux system with Nvidia hardware and running OpenGL 1.4). In case any of this makes sense, I will include the structure of the openGL calls below:


glutInit (&argC, argV);

glutInitWindowPosition (100, 100);
createGraphics ();
glEnable (GL_DEPTH_TEST);
glClearColor (0., 0., 0., 1.);
glutMainLoop ();


width = 700;
height = 600;

glutInitWindowSize (width, height);
glutCreateWindow ("TITLE");
glClearColor (0, 0., 0., 1.);
glutDisplayFunc (drawBeams);
glutReshapeFunc (changeSize);
glutPostRedisplay ();
glutTimerFunc (0, check_for_data, 0);


glMatrixMode (GL_PROJECTION);
glPushMatrix ();
gluOrtho2D (0., width, 0., height);

glViewport (0, 100, width - 100, height - 100);
glutSwapBuffers ();

glViewport (0, 0, (GLsizei) w, (GLsizei) h);

int widthLocal = 599 - currentBeam;

glRasterPos2i (widthLocal, 150);
glDrawPixels (currentBeam, 500, GL_RGBA, GL_FLOAT, da);
glFlush ();
glutSwapBuffers ();

gets data from shared memory
converts data into rgba array called da
calls drawArray

glutTimerFunc (10, check_for_data, 0);

I would appreciate it if anyone can tell me what I am doing wrong, as I obviously don't have a grasp on openGL yet. Any advice I can get from you OpenGL gurus out there is greatly appreciated. Thanks in advance for your time and patience!

02-10-2011, 06:15 PM
One thing I could suggest is that u recheck the data in your array may be you are missing some data. Disable the timer and just use the keyboard right/left arrow keys to move the points and see if ur data is fine.

02-10-2011, 06:58 PM
Thank you. I have verified that the last few ranges of the first few beams do exist. In fact each time they get redrawn a few more y values show up. I'll try disabling the timer tomorrow and maybe slowing down the data flow. I'll let you know if I figure anything out. Thanks again!

02-16-2011, 03:14 PM
I want to thank you for your suggestions. I did as you said and was finally able to figure out that I was putting the data into the image array incorrectly. Thank you so much for your time and willingness to help. I have more questions, but should post them separately. Thanks again!