Thread: [sdljava-users] Incorrect behaviour of glTranslatef() on Linux?
Status: Beta
Brought to you by:
ivan_ganza
From: Raffael H. <her...@ra...> - 2005-12-20 18:08:09
|
Hi, I'm having a strange problem with sdljava on Ubuntu Linux (Breezy). I=20 was trying go through the NeHe tutorials, but I already failed in the=20 first lesson because glTranslatef() seems to behave very strangely=20 (maybe incorrectly?). =46irst the Code: gl.glLoadIdentity(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glColor3f(1.0f, 1.0f, 1.0f); // added by me, to be sure gl.glTranslatef(-1.5f, 0f, -6f); gl.glBegin(GL.GL_POLYGON); gl.glVertex3f(0.0f, 1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glEnd(); gl.glTranslatef(3.0f, 0.0f, 0.0f); gl.glBegin(GL.GL_QUADS); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 0.0f); gl.glEnd(); gl.flush(); surface.glSwapBuffers(); The problematic line is the 4th one: "gl.glTranslatef(-1.5f, 0f, -6f);" Like this, all I get is a black window. If I change -6f to 0f, it works=20 correctly, but of course, it's too big, that's why we want to move back=20 first. ;) The strange thing now is: If I change it to 1f or -1f, I get exactly the=20 same picture as with 0f. If, however, I change it to 1.1f or -1.1f, I'm=20 back at the black window. The x and y axis seem to work correctly. Do I have to set some flag somewhere with sdljava or is this actually a=20 bug in sdljava (or maybe some sort of incompatibility with Breezy)? Both OpenGL tests shipped with sdljava work fine BTW, but they don't use=20 glTranslatef(). Oh, and another thing, I also tried replacing=20 glTranslatef() with glTranslated(), but that's just the same thing. TIA, Raffi =2D-=20 The difference between theory and practice is that in theory, there is no difference, but in practice, there is. he...@ra... =B7 ICQ#67961355 =B7 PGP Key 5D1FF5F4 =B7 www.raffael.ch |
From: Ivan Z. G. <iva...@ya...> - 2005-12-23 02:51:56
|
Hi Raffael, I would have to gamble that glTranslatef() is working correctly. The reason is that sdljava only delegates the call to the OpenGL layer and does nothing special itself. Unless something funny is happening to the numbers before they get to the OpenGL layer I can't imagine there to be a problem. Conversion of the numbers appropriatly is taken care of by swig so this should be fairly solid... Sorry that I can't be more help. -Ivan/ Raffael Herzog wrote: >Hi, > >I'm having a strange problem with sdljava on Ubuntu Linux (Breezy). I >was trying go through the NeHe tutorials, but I already failed in the >first lesson because glTranslatef() seems to behave very strangely >(maybe incorrectly?). > >First the Code: > > gl.glLoadIdentity(); > gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); > gl.glColor3f(1.0f, 1.0f, 1.0f); // added by me, to be sure > gl.glTranslatef(-1.5f, 0f, -6f); > > gl.glBegin(GL.GL_POLYGON); > gl.glVertex3f(0.0f, 1.0f, 0.0f); > gl.glVertex3f(-1.0f, -1.0f, 0.0f); > gl.glVertex3f(1.0f, -1.0f, 0.0f); > gl.glEnd(); > > gl.glTranslatef(3.0f, 0.0f, 0.0f); > > gl.glBegin(GL.GL_QUADS); > gl.glVertex3f(-1.0f, 1.0f, 0.0f); > gl.glVertex3f(1.0f, 1.0f, 0.0f); > gl.glVertex3f(1.0f, -1.0f, 0.0f); > gl.glVertex3f(-1.0f, -1.0f, 0.0f); > gl.glEnd(); > > gl.flush(); > surface.glSwapBuffers(); > >The problematic line is the 4th one: "gl.glTranslatef(-1.5f, 0f, -6f);" > >Like this, all I get is a black window. If I change -6f to 0f, it works >correctly, but of course, it's too big, that's why we want to move back >first. ;) > >The strange thing now is: If I change it to 1f or -1f, I get exactly the >same picture as with 0f. If, however, I change it to 1.1f or -1.1f, I'm >back at the black window. The x and y axis seem to work correctly. > >Do I have to set some flag somewhere with sdljava or is this actually a >bug in sdljava (or maybe some sort of incompatibility with Breezy)? > >Both OpenGL tests shipped with sdljava work fine BTW, but they don't use >glTranslatef(). Oh, and another thing, I also tried replacing >glTranslatef() with glTranslated(), but that's just the same thing. > >TIA, > Raffi > > > |
From: Raffael H. <her...@ra...> - 2005-12-23 09:03:10
|
Ivan Z. Ganza schrieb: > I would have to gamble that glTranslatef() is working correctly. The > reason is that sdljava only delegates the call to the OpenGL layer > and does nothing special itself. Yes, I actually thought so too, but the behaviour was so funny ... ;) Yesterday I managed to figure out what was going wrong by looking at a=20 C/SDL 'port' of the tutorial code. This code did some more OpenGL=20 initialization before the 1:1 port of the tutorial: gl.glEnable(GL.GL_TEXTURE_2D); gl.glShadeModel(GL.GL_SMOOTH); gl.glClearColor(0f, 0f, 0f, 0f); gl.glClearDepth(1); gl.glEnable(GL.GL_DEPTH_TEST); gl.glDepthFunc(GL.GL_LEQUAL); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.gluPerspective(45f, (float)width/(float)height, .1f, 100f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); By experiments I found that the call to gluPerspective() while in matrix=20 mode GL_PROJECTION is the important action here which makes things=20 working as they should. I'm sure, some time I'll even understand=20 why. ;) cu & thanks, Raffi =2D-=20 The difference between theory and practice is that in theory, there is no difference, but in practice, there is. he...@ra... =B7 ICQ#67961355 =B7 PGP Key 5D1FF5F4 =B7 www.raffael.ch |