Im reading the file fine, but I cant get a picture using opengl.
thank you
code
#include <iostream.h>
#include <fstream.h>
#include <GL/glut.h>
GLuint Picture;
static void init (void){
glClearColor (1.0, 1.0, 1.0, 0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 200.0, 0.0, 150.0);
Picture = glGenLists (1);
glNewList (Picture, GL_COMPILE);
int x, y;
ifstream infile ("picture.dat");
ofstream outfile ("chris.txt");
glBegin (GL_LINES);
while (!infile.eof()){
infile >> x >> y;
glVertex2i(x,y);
glEnd();
glEndList ();
outfile <<x<<""<<y<<" ";
cout<<endl;
}
infile.close();
outfile.close();
}
void lineSegment (void){
glClear (GL_COLOR_BUFFER_BIT);
glCallList (Picture);
glFlush ();
}
void main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (50,100);
glutInitWindowSize (400,300);
glutCreateWindow (“Hello”);
init ();
glutDisplayFunc (lineSegment);
glutMainLoop ();
}
[This message has been edited by chris197213 (edited 02-07-2004).]
I think a little more information would help, there could be a thousand diffrent reasons for no image.
How about post the code!
Originally posted by chris197213:
Im reading the file fine, but I cant get a picture using opengl.
thank you
Honk
February 7, 2004, 6:43pm
3
Here is the whole thing with proper indenting.
As you can see glEnd() and glEndList() is called within the loop so GL_LINES only gets the inital set of x/y coordinates and then glEnd and glEndList() is called and that will cause the following calls in that loop to fail.
#include <iostream.h>
#include <fstream.h>
#include <GL/glut.h>
GLuint Picture;
static void init (void)
{
glClearColor (1.0, 1.0, 1.0, 0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 200.0, 0.0, 150.0);
Picture = glGenLists (1);
glNewList (Picture, GL_COMPILE);
int x, y;
ifstream infile (“picture.dat”);
ofstream outfile (“chris.txt”);
lBegin (GL_LINES);
while (!infile.eof())
{
infile >> x >> y;
glVertex2i(x,y);
glEnd();
glEndList();
outfile <<x<<“”<<y<<" ";
cout<<endl;
}
infile.close();
outfile.close();
}
void lineSegment (void)
{
glClear (GL_COLOR_BUFFER_BIT);
glCallList (Picture);
glFlush ();
}
void main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (50,100);
glutInitWindowSize (400,300);
glutCreateWindow (“Hello”);
init();
glutDisplayFunc(lineSegment);
glutMainLoop();
}
With the ortho projection, is your object draw between -1 and 1 on the Z axis.
You may need to translate it to the correct location on the screen to be seen.