   JOGL (Java)  various questions
  I just decided to stick with OpenGL. Weeks ago, I was twisting my head with DirectX and C/C++. Now I started with Java, and I want to learn OpenGL, using JOGL. I already know some things, about OpenGL and about 3D graphics.   I want to jump directly into Matrix, VBO and modeling, so I'd like to know some specific details.   I don't want to waste too much of your time, so I first "googled" the things that I wanted to read about, and then, posted here.  1) As I can see, both DirectX and OpenGL use matrix for positioning the camera and the objects in the scene. In DX is quite obvious how matrix are handled, but in OpenGL is a bit confusing. Not the stack is the problem, nor the sequence of translations/rotations, but I couldn't find clearly a function to load or save a matrix.  2) About VBO. In DirectX I could use a structure to hold all the information about a vertex (whatever I need: x,y,z, color, texture coordinates). In OpenGL it seems that I should use up to 6 arrays, each one holding a kind of information.   In order to hold together the vertex information, I could only find one trick to mix up several arrays (Interleaved Arrays). Is this the only method? Is it possible for this to slightly slow down the rendering process?  3) Is it possible to save (in a bitmap, let's say) the color buffer? Let's say I render some objects in a room, then I want to save the result as a picture, in order to load it whenever I want. This would be cool if only a few objects in the room were animated. Also, I could use this for some further processing (pixel-by-pixel let's say). One idea would be rendering to texture, but I think I would prefer some sort of a bitmap for this job.Right now I'm focused on the first question. I want to practice some modeling and animations. I think that if I animate a robot (let's say), it would be fast to store a sequence of matrix, in order to quickly determine the position of each of its member.[EDIT: I think I just found a part of the answer for the first question. The function glLoadTransposeMatrixf should load my matrix. Now I should find a way to retrieve a matrix from OpenGL][Edited by - chri5ty on June 15, 2009 11:28:14 AM]
Quote:Original post by chri5tyI couldn't find clearly a function to load or save a matrix.glLoadMatrix, glGet(GL_MODELVIEW_MATRIX).Quote:In order to hold together the vertex information, I could only find one trick to mix up several arrays (Interleaved Arrays). Is this the only method? Is it possible for this to slightly slow down the rendering process?In the past interleaved arrays were supposed to be slightly faster, however my experience has been that they've been near identical to non-interleaved data. Usually I don't use glInterleavedArrays but instead just use gl*Pointer with appropriate stride and offset parameters.Quote:Is it possible to save (in a bitmap, let's say) the color buffer?glReadPixels.   ;  WOW! That was fast reply! I think this is specific to the GameDev community ;))Thanks a lot for the hints. These functions are more that just useful. I'll do my work fast, and come back with further questions.   ;  For half an hour, I've been trying to figure out why saving a matrix doesn't work.import javax.media.opengl.GL;public class Matrix {public float mat[]=new float[16];public static enum Types{PROJECTION,MODELVIEW,TEXTURE}public void load(final GL gl,Types matrixType){if(matrixType==Types.MODELVIEW)gl.glMatrixMode(GL.GL_MODELVIEW);else if(matrixType==Types.PROJECTION)gl.glMatrixMode(GL.GL_PROJECTION);else if(matrixType==Types.TEXTURE)gl.glMatrixMode(GL.GL_TEXTURE);gl.glLoadMatrixf(mat,0);}public void save(final GL gl,Types matrixType){if(matrixType==Types.MODELVIEW)gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX,mat,0);else if(matrixType==Types.PROJECTION)gl.glGetFloatv(GL.GL_PROJECTION_MATRIX,mat,0);else if(matrixType==Types.TEXTURE)gl.glGetFloatv(GL.GL_TEXTURE_MATRIX,mat,0);int i=0;for(;i<16;i++)System.out.print(" "+mat);System.out.println();}}I try to save a matrix, line this:    gl.glMatrixMode(GL.GL_MODELVIEW_MATRIX); //To be sure  gl.glLoadIdentity();    gl.glTranslatef(0.0f, 0.0f, -4.0f);    gl.glRotatef(r, 1.0f, 0.0f, 0.0f);    gl.glRotatef(r, 0.0f, 1.0f, 0.0f);    gl.glRotatef(r, 0.0f, 0.0f, 1.0f);    gl.glRotatef(r, 0.0f, 1.0f, 0.0f);mat.save(gl,Types.MODELVIEW); //Here! This doesn't workThe variable "r" increases every frame (no doubt). At the beginning of every frame, I load this matrix. This works fine. Still, the "save" function doesn't work; It outputs always the same initial values (println).   ;  Don't know much about JOGL, but when setting matrix mode, use GL_MODELVIEW instead of GL_MODELVIEW_MATRIX (that is used only for glGet() functions)Other than that, the code seems ok.;  JOGL and OpenGL shouldn't have differences at all. The only ones are related to arrays. Either I have to use some classes like IntBuffer,FloatBuffer (implementing Buffer) to wrap around an array, either I have to specify the reference of an array and an offset.Following the documentation, this code should be OK. I use glMatrixMode(GL_MODELVIEW); to set the matrix mode before drawing (and actually there is no problem with this), and  glGetFloatv(GL_MODELVIEW_MATRIX,mat); to retrieve a matrix. I also tried the other combination with GL_MODELVIEW and GL_MODELVIEW_MATRIX. The "save" function fails with both parameters, but the "load" function works only with GL_MODELVIEW.It's a bit strange that the "load" function works only once.   ;Quote:Original post by chri5tyFor half an hour, I've been trying to figure out why saving a matrix doesn't work.Personally, I recommend using glGetError() often. This way, you will know when you made a mistake.Also, the documents are usefulhttp://www.opengl.org/sdk/docs/man/http://www.opengl.org/wiki;  These guys seem to have had the same problem...http://www.gamedev.net/community/forums/topic.asp?topic_id=532342http://www.gamedev.net/community/forums/topic.asp?topic_id=190301   