PDA

View Full Version : problem with glcopyteximage in LWJGL



D3GAN
01-31-2011, 10:33 AM
hi everyone

I am triyng to write a code in LWJGL that draw a table with some texture on every cell
then i want to take a screenshot from my window and use this picture as a texture for a cube ...
but i face problem with glcopyteximage2d ...
this func take screenshot but in it you cant see my texture that i map them to cells of my table ...
this is my code..
thank you for your time


private void render(int flag)
{
if(flag==0){ GL11.glClear(GL11.GL_COLOR_BUFFER_BIT|GL11.GL_DEPT H_BUFFER_BIT);
GL11.glLoadIdentity();
GL11.glPushMatrix();

GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(-ortho_x/2,ortho_x/2,-ortho_y/2,ortho_y/2);
GL11.glMatrixMode(GL11.GL_MODELVIEW);

float quad_H=(ortho_y-offset)/quads_num;
float quad_W=(ortho_x-offset)/quads_num;
for(int i=0;i<quads_num;i++){
for(int j=0;j<quads_num;j++){
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glTexEnvi(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_ ENV_MODE,GL11.GL_BLEND);
texture.bind();
GL11.glBegin(GL11.GL_POLYGON);
GL11.glColor3f(1,0,0);
GL11.glTexCoord2f(0, (float) .75);GL11.glVertex2d((-ortho_x/2)+offset/2+i*quad_W,(-ortho_y/2)+offset/2+j*quad_H);
GL11.glTexCoord2f(0,0);GL11.glVertex2d((-ortho_x/2)+offset/2+i*quad_W,(-ortho_y/2)+offset/2+(j+1)*quad_H);
GL11.glTexCoord2f((float) .75,0);GL11.glVertex2d((-ortho_x/2)+offset/2+(i+1)*quad_W,(-ortho_y/2)+offset/2+(j+1)*quad_H);
GL11.glTexCoord2f((float).75,(float).75);GL11.glVe rtex2d((-ortho_x/2)+offset/2+(i+1)*quad_W,(-ortho_y/2)+offset/2+(j)*quad_H);
GL11.glEnd();

GL11.glLineWidth(3);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBegin(GL11.GL_LINES);
GL11.glColor3f(0,0,1);
GL11.glVertex2d((-ortho_x/2)+offset/2+i*quad_W,(-ortho_y/2)+offset/2+j*quad_H);
GL11.glVertex2d((-ortho_x/2)+offset/2+i*quad_W,(-ortho_y/2)+offset/2+(j+1)*quad_H);
GL11.glVertex2d((-ortho_x/2)+offset/2+i*quad_W,(-ortho_y/2)+offset/2+j*quad_H);
GL11.glVertex2d((-ortho_x/2)+offset/2+(i+1)*quad_W,(-ortho_y/2)+offset/2+(j)*quad_H);
GL11.glEnd();
}
GL11.glEnd();
}
for(int i=0;i<quads_num;i++){
GL11.glBegin(GL11.GL_LINES);
GL11.glVertex2d((-ortho_x/2)+offset/2+i*quad_W,(-ortho_y/2)+offset/2+(quads_num)*quad_H);
GL11.glVertex2d((-ortho_x/2)+offset/2+(i+1)*quad_W,(-ortho_y/2)+offset/2+(quads_num)*quad_H);

GL11.glVertex2d((-ortho_x/2)+offset/2+(quads_num)*quad_W,(-ortho_y/2)+offset/2+(i)*quad_H);
GL11.glVertex2d((-ortho_x/2)+offset/2+(quads_num)*quad_W,(-ortho_y/2)+offset/2+(i+1)*quad_H);
GL11.glEnd();
}
GL11.glPopMatrix();
//GL11.glEnable(GL11.GL_TEXTURE_2D);
render(1);
}

else{

//GL11.glLoadIdentity();
GL11.glPushMatrix();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
//GLU.gluPerspective(45.0f,((float)targetWidth)/((float)targetHeight),0.1f,100.0f);
GL11.glOrtho(-10, 10,-10,10,-10,10);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D,0,GL11.GL _RGBA,0,0,Display.getDisplayMode().getWidth(),Disp lay.getDisplayMode().getHeight(),0);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT|GL11.GL_DEPT H_BUFFER_BIT);
GL11.glTexEnvi(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_ ENV_MODE,GL11.GL_REPLACE);
GL11.glBegin(GL11.GL_POLYGON);
GL11.glTexCoord2f(0,0);GL11.glVertex2f(-5,-5);
GL11.glTexCoord2f(0,1);GL11.glVertex2f(5,-5);
GL11.glTexCoord2f(1,1);GL11.glVertex2f(5,5);
GL11.glTexCoord2f(1,0);GL11.glVertex2f(-5,5);
GL11.glEnd();
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glPopMatrix();
}
}

mhagain
01-31-2011, 11:30 AM
I'm having serious difficulty lining up your code blocks with your opening and closing braces here - could you consider reformatting your code, please?