Re: [Plib-users] using triangles
Brought to you by:
sjbaker
|
From: Steve B. <sjb...@ai...> - 2002-03-29 15:40:02
|
Sami Partinen wrote: > > ----- Original Message ----- > From: "Steve Baker" <sjb...@ai...> > > I think the only problem is that we aren't looking in the direction of > > the triangle you are drawing - or perhaps the triangle is being backface > > culled. > > Hi, > now I've been tried to get that thing work in several "days" > and I'm just sure that this way is not correct way to try that > thing. I did even half shorter version, which redraw is 100% > identical with my raw opengl version, which works fine. > I think that problem is this gcc in linux, or something like > that, because plib objects works normally. I very much doubt it's GCC/Linux...in all the years I've been using it, I've never seen an actual compiler error that affected 'normal' C/C++ code. (Although I have seen two CPU design errors!) > Anyway, latest "triangle" version found from here, > and seems that it don't even go to redraw routine > or at least it don't run that swapbuffers line. > http://www.saunalahti.fi/~saparti/samitest.cpp Yes - you seem to have deleted the line in 'redraw' that tells it to trigger another redraw. By default, GLUT only calls your redraw callback if there is a reason to do so (like you moved the window, resized it or uncovered it by moving another window). When you are doing animation, you need to redraw the screen continuously. Hence you need to call: glutPostRedisplay () ; ...either somewhere in the 'redraw' function itself - or in some kind of timer routine. I generally toss it into 'redraw' as the last line of the function before I return to GLUT. > If there is any source code example which use > raw opengl too, it would be a welcome. I really would > be a happy from any example. Well, this list isn't really for teaching people OpenGL but in the interests of getting on with life, here is an example program I wrote for the book "Linux Game Programming": /* Compile me with: cc -c ex4.c cc -o ex4 ex4.o -L/usr/X11/lib -lglut -lGLU -lGL -lX11 -lXext -lm */ #include <math.h> #include <GL/gl.h> /* Include definitions of the OpenGL API */ #include <GL/glut.h> /* Include definitions of the GLUT API */ extern void redisplay ( void ) ; extern void initCamera ( void ) ; int main ( int argc, char **argv ) { glutInit ( &argc, argv ) ; glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ) ; glutInitWindowSize ( 640, 480 ) ; glutCreateWindow ( "My First OpenGL Program" ) ; glutDisplayFunc ( redisplay ) ; initCamera () ; glutMainLoop () ; return 0 ; } void initCamera ( void ) { /* Select the Projection matrix */ glMatrixMode ( GL_PROJECTION ) ; glLoadIdentity(); #if 0 glOrtho(-1,1,-1,1,-1,1); #else gluPerspective ( 40.0, 1.333, 0.1, 100000.0 ) ; #endif /* Go back to the ModelView matrix */ glMatrixMode ( GL_MODELVIEW ) ; } void redisplay ( void ) { #define ROTATION_SPEED 1.0f static float a = 0 ; static float pos [ 3 ] = { 1000.0f, 5000.0f, 0.0f } ; glEnable ( GL_DEPTH_TEST ) ; glClearColor ( 0.0f, 0.5f, 0.0f, 1.0f ) ; /* Dark Green */ glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; a += ROTATION_SPEED ; glLoadIdentity () ; glTranslatef ( 0.0f, 0.0f, -10.0f ) ; glLightfv ( GL_LIGHT0, GL_POSITION, pos ) ; glRotatef ( a, 0.0f, 0.0f, 1.0f ) ; glBegin ( GL_TRIANGLES ) ; /* Start describing triangles */ glColor3f ( 1.0f, 0.0f, 0.0f ) ; /* Red */ glVertex3f ( 0.0f, 0.0f, 0.0f ) ; /* First triangle */ glVertex3f ( -1.0f, -1.0f, -1.0f ) ; glVertex3f ( 1.0f, -1.0f, -1.0f ) ; glColor3f ( 0.0f, 1.0f, 0.0f ) ; /* Green */ glVertex3f ( 0.0f, 0.0f, 0.0f ) ; /* Second triangle */ glVertex3f ( 1.0f, -1.0f, -1.0f ) ; glVertex3f ( 0.0f, 1.0f, -1.0f ) ; glColor3f ( 0.0f, 0.0f, 1.0f ) ; /* Blue */ glVertex3f ( 0.0f, 0.0f, 0.0f ) ; /* Third triangle */ glVertex3f ( 0.0f, 1.0f, -1.0f ) ; glVertex3f ( -1.0f, -1.0f, -1.0f ) ; glColor3f ( 1.0f, 1.0f, 0.0f ) ; /* Yellow */ glVertex3f ( -1.0f, -1.0f, -1.0f ) ; /* Fourth triangle */ glVertex3f ( 0.0f, 1.0f, -1.0f ) ; glVertex3f ( 1.0f, -1.0f, -1.0f ) ; glEnd () ; /* All done - let the drawing commence. */ glutSwapBuffers () ; glutPostRedisplay () ; } ----------------------------- Steve Baker ------------------------------- Mail : <sjb...@ai...> WorkMail: <sj...@li...> URLs : http://www.sjbaker.org http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net http://freeglut.sf.net http://toobular.sf.net http://lodestone.sf.net |