PDA

View Full Version : Using gl.glTexSubImage2D



sonnik
04-13-2009, 08:11 AM
Hi

I am using gl.glTexSubImage2D to update my current texture.
This is what I am trying to do:

1. I have a blank texture which I am attaching to the sides of the cube.
2. I am updating the texture necessary to have Text written on it in real time. I need 3 different lines on the texture to be updated at 3 different times. So, I am trying to use gl.glTexSubImage2D to update the current Texture.

Can you please tell me if this approach is proper. Also I am getting this error:
Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: unpack pixel_buffer_object must be enabled to call this method

when I call:


glut.glutBitmapString(GLUT.BITMAP_TIMES_ROMAN_10, "text is here!!!!!");
gl.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, 12, 44, 16, 16,GL.GL_RGB, GL.GL_UNSIGNED_BYTE,0);

Please let me know the procedure to do such a thing as I am having a feeling that I am messing somewhere.

Thanks in advance.

ephtracy
04-13-2009, 10:02 AM
may use 'glCopyTexSubImage2D',
this one is for copying from frame buffer to part of texture

sonnik
04-13-2009, 02:15 PM
Can you please elaborate?

I am not too familiar with all these stuff

sonnik
04-14-2009, 10:31 PM
THIS IS THE CODE:

PLEASE DISREGARD THE THIN BLACK LINES WHICH ARE SEEN ON THE IMAGE. THEY ARE THE PART OF THE CODE. I AM CONCERNED ABOUT THE BLACK PATCH WHICH IS COMING UP INSTEAD OF THE TEXT.

can you please let me know what I am doing wrong? This is really urgent.

Thanks in advance.


public void init(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
glut = new GLUT();

gl.glClearColor(0.8f, 0.7f, 0.5f, 0.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
gl.glShadeModel(GL.GL_SMOOTH);
gl.glEnable(GL.GL_TEXTURE_2D);


texture = genTexture(gl);



gl.glCopyTexImage2D(GL.GL_TEXTURE_2D, 0 , GL.GL_RGB, -1, 0, 128, 128, 0);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);


gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);


}



public void display(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
GLU glu = new GLU();
GLUT glut = new GLUT();

gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// Reset The Current Modelview Matrix
gl.glEnable(GL.GL_CULL_FACE);

gl.glLoadIdentity();

gl.glTranslatef(3.0f, 0.0f, -15.0f);

gl.glRotatef(rotqube/5,0.0f,1.0f,0.0f); // Rotate The cube around the Y axis


WriteText(drawable);

gl.glBegin(GL.GL_QUADS); // Draw The Cube Using quads
Drawcube(drawable);
gl.glEnd(); // End Drawing The Cube
DrawDivideLines(drawable);

rotqube ++;
if (rotqube/50 >= 360.f)
rotqube = 0.0f;

}



public void WriteText(GLAutoDrawable drawable){

GL gl = drawable.getGL();
GLUT glut = new GLUT();

gl.glPushMatrix();

gl.glLoadIdentity();
gl.glRasterPos3f(0, 0, 0);
glut.glutBitmapString(GLUT.BITMAP_TIMES_ROMAN_10, "write text here");
gl.glCopyTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0, 80, -40, 128,60);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

gl.glPopMatrix();
}