View Full Version : Very Urgent: how to display image from text based image information with OpenGL

kedar pawar
01-31-2005, 02:20 AM
Hello there,
I am New for OpenGL.
I have image information (pixels, color, depth, etc)in the ASCII file. I wanted to display image with the pure openGL cdoe. The file information format is like follow:

image Heiight: 500
Image Width : 500
Object x1 y1 x2 y2 Color(R,G,B) depth
Line1 20 10 20 55 (254,120,126) x
Line2 30 10 60 5 (25,120,226) x
Rect 99 30 200 170 (225,225,225) x
Line3 20 10 20 55 (154,120,126) x
Rect 10 20 100 70 (150,30,150) x

Above is table represents the information of image. I want to display image with OpenGL
How can i do this with OpenGL.
Is there any sample code available? please help me ..... ...


01-31-2005, 10:01 AM
The easiest approach, is to create an STL vector or a C array to hold the values for each object. To do this you would need to parse the line to get each number and then use a C function like atoi() to get the integer and cast it to unsigned char (I don't know if there's an ato*() function that returns a char or unsigned char, probably not) and then store it in the vector.
Then in your render function, iterate through each vector and draw the objects. You could hold different vectors for each primitive or store the primitive's type as well and change the call to glBegin-glEnd accordingly. However the first approach would provide some optimization, as you can have one glBegin-glEnd pair for each primitive.