Thread: Re: [Plib-users] using triangles
Brought to you by:
sjbaker
|
From: <sa...@sa...> - 2002-03-25 12:30:37
|
Hi Steve, thanks from quick answer. >. >. > Well, that *could* be it - but it's hard to know without > seeing the entire program. I tried to parse everything out, except that triangle. It still didn't work. Here is code from that parsed version http://www.saunalahti.fi/~saparti/samitest.cpp I still wonder, what would be a correct order when I have those ships and other things in there too. Example: void redraw (){ update_motion () ; glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; ssgCullAndDraw ( scene ) ; glutPostRedisplay () ; glutSwapBuffers () ; } Should I put those raw opengl things between ssgCullAndDraw line and glutPostRedisplay line? Is that glutSwapBuffers that command, which throw those raw opengl things to the screen? These might be some newbie guestions, but from somewhere everyone should start :) > Can you post more of the program - or (preferably) put it > onto a web site somewhere where we could download the > sources and look at them? I wish that those mistakes are in that parsed version which is upper to this message. > If I had to guess, I'd say that disabling backface culling > and texturing would fix your problem...but it's hard to > diagnose this without seeing more code. Seems that this time I didn't use 2 sided polygons :/ might be that one, but could be a problems with perspective. Now in that code could be very weird look settings, I just tried so many rotations and translates. Sami |
|
From: Steve B. <sjb...@ai...> - 2002-03-25 13:17:30
|
sa...@sa... wrote: > I tried to parse everything out, except that triangle. It still didn't > work. Here is code from that parsed version > http://www.saunalahti.fi/~saparti/samitest.cpp OK - I'll take a look at it. > I still wonder, what would be a correct order when I have those ships > and other things in there too. > > Example: > void redraw (){ > update_motion () ; > glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; > ssgCullAndDraw ( scene ) ; > glutPostRedisplay () ; > glutSwapBuffers () ; > } > > Should I put those raw opengl things between ssgCullAndDraw line and > glutPostRedisplay line? Yes. > Is that glutSwapBuffers that command, which throw those raw opengl > things to the screen? These might be some newbie guestions, but from > somewhere everyone should start :) The screen is a chunk of memory holding the pixels and the Z values - right? Well, in OpenGL there are TWO chunks of pixel memory - one for the screen that you are looking at on the CRT and the other for the one that you are drawing into. When you have completely finished drawing, the picture you were drawing is swapped with the one you *were* looking at so now you are looking at the new one and the old one is 'recycled' to be used as the next place to draw into. (That's an oversimplification - but not in any respect that matters) ----------------------------- 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 |
|
From: Steve B. <sjb...@ai...> - 2002-03-26 00:33:12
|
sa...@sa... wrote: > > I tried to parse everything out, except that triangle. It still didn't > work. Here is code from that parsed version > http://www.saunalahti.fi/~saparti/samitest.cpp Well, let's look at the 'redraw' routine. I have a few comments: * No need to issue a scale command if the scales are all '1' glScalef(1,1,1); * You already cleared the screen once - no need to do it again! glClear( GL_COLOR_BUFFER_BIT ); 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. ----------------------------- 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 |
|
From: Sami P. <sam...@sa...> - 2002-03-29 14:56:03
|
----- 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. 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 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. Now I've been done lot of work with simple triangle without any results. This VCR algorithm should be 100 times harder job, and it works already. Sami |
|
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 |