Login  Register

Re: vbo draw elements vs image draw pixels - strange difference

Posted by rtayek on Sep 04, 2012; 5:50am
URL: https://forum.jogamp.org/vbo-draw-elements-vs-image-draw-pixels-strange-difference-tp4026002p4026018.html

i got my texture to work ok. vbo and image are working also. image is peculiar in that it does not rotate with everything else, but that may not be a problem since this is supposed to be a 2d app.

i have a 1024x1024 image of java.awt.Color in all cases.

my texture code (please see below) is kinda slow because i am calling init() inside render(). i need to do some of this since the color values in the image will change over time.

can any of the code in init() be moved out of render()? i think i am asking which call causes the data in the direct buffer to be moved to the graphics card.

would using the vbo technique or an image be preferable (faster)?

vbo sorta seems like overkill. since it need an additional 6 mb for the vertex and indices (the 1024x1024 really wants to be 2048x2048).

thanks
 


        void init(GLAutoDrawable drawable) {
                if(++count%2==0)
                        create(); // makes a green square
                else change(); // makes red square
                putImageIntoBuffer();
                GL2 gl=drawable.getGL().getGL2();
                TextureData textureData=new TextureData(GLProfile.getDefault(),GL_RGBA,2*radius,2*radius,0,GL_RGBA,GL_UNSIGNED_BYTE,false,false,true,byteBuffer,(Flusher)null);
                texture=TextureIO.newTexture(textureData);
                gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
                gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
                TextureCoords textureCoords=texture.getImageTexCoords();
                textureTop=textureCoords.top();
                textureBottom=textureCoords.bottom();
                textureLeft=textureCoords.left();
                textureRight=textureCoords.right();
        }
        public void render(GLAutoDrawable drawable) {
                init(drawable);
                final GL2 gl=drawable.getGL().getGL2();
                gl.glPushMatrix();
                final Color color=Color.white;
                setColor(color,gl);
                if(!once) {
                        System.out.print("t2 color is ");
                        printColor(gl);
                }
                gl.glEnableClientState(GL_TEXTURE_COORD_ARRAY);
                texture.enable(gl);
                texture.bind(gl);
                Vector3d ll=new Vector3d(-1,-1,0);
                Vector3d lr=new Vector3d(1,-1,0);
                Vector3d ur=new Vector3d(1,1,0);
                Vector3d ul=new Vector3d(-1,1,0);
                if(!once)
                        System.out.println("texture from ctor: "+ll+" "+lr+" "+ur+" "+ul);
                ll.scaleAdd(scaleFactor,offset);
                lr.scaleAdd(scaleFactor,offset);
                ur.scaleAdd(scaleFactor,offset);
                ul.scaleAdd(scaleFactor,offset);
                if(!once) {
                        System.out.println("texture from ctor: "+ll+" "+lr+" "+ur+" "+ul);
                        once=true;
                }
                gl.glBegin(GL_QUADS);
                gl.glTexCoord2f(textureLeft,textureBottom);
                gl.glVertex3d(ll.x,ll.y,ll.z);
                gl.glTexCoord2f(textureRight,textureBottom);
                gl.glVertex3d(lr.x,lr.y,lr.z);
                gl.glTexCoord2f(textureRight,textureTop);
                gl.glVertex3d(ur.x,ur.y,ur.z);
                gl.glTexCoord2f(textureLeft,textureTop);
                gl.glVertex3d(ul.x,ul.y,ul.z);
                gl.glEnd();
                texture.disable(gl);
                gl.glDisableClientState(GL_TEXTURE_COORD_ARRAY);
                gl.glPopMatrix();
        }