Texture bug

Started by pdufranc, November 09, 2005, 06:59:11

Previous topic - Next topic

pdufranc

////////////////////////////////////////////// 
// create canvas in jframe with thread ( thread -> canvas.repaint();) 

canvas = new AWTGLCanvas() { 
                long startTime = 0; 
                long fps = 0; 
                public void paintGL() { 

                    if (startTime == 0) { 
                        setup(); 
                        startTime = System.currentTimeMillis() + 5000; 
                    } 
                    try { 
                        makeCurrent(); 
                        myRender(); 
                        swapBuffers(); 
                    } catch (LWJGLException e) { 
                        throw new RuntimeException(e); 
                    } 
                } 
            }; 
        } catch (RuntimeException ex) { 
        } catch (LWJGLException ex) { 
        } 
canvas.setBounds(0, 0, width, height); 

////////////////////////////////////////////// 
//Setup 

byte[] pixels; 
int cpt=0; 
pixels = new byte[textureWidth * textureHeight * textureMode]; 
boolean state=true; 
for (int i = 0; i < textureWidth; i++) { 
    for (int j = 0; j < textureHeight; j++) { 
   //pixels[cpt] = (byte) 0xFF; ; 
   if (state){ 
       pixels[cpt] = (byte) 0; 
       cpt++; 
       pixels[cpt] = (byte) 1; 
       cpt++; 
       state=false; 
   } 
   else{ 
       pixels[cpt] = (byte) 1; 
       cpt++; 
       pixels[cpt] = (byte) 0; 
       cpt++; 
       state=true; 

   } 
   pixels[cpt] = 0; 
   cpt++; 
   pixels[cpt] = 0; 
   cpt++; 

    } 
} 
GL11.glEnable(GL11.GL_TEXTURE_2D); 
ByteBuffer scratch = ByteBuffer.wrap(pixels); 
scratch = ByteBuffer.allocateDirect(textureWidth * textureHeight * textureMode); 
scratch.position(0); 
idTexture = BufferUtils.createIntBuffer(1); 
GL11.glEnable(GL11.GL_TEXTURE_2D); 
GL11.glGenTextures(idTexture); // Create Texture In OpenGL 

GL11.glBindTexture(GL11.GL_TEXTURE_2D, idTexture.get(0)); 
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, 
           GL11.GL_NEAREST); 
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, 
           GL11.GL_NEAREST); 
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, 
            textureWidth, 
            textureHeight, 0, GL11.GL_RGBA, 
            GL11.GL_UNSIGNED_BYTE, scratch); 

GL11.glDisable(GL11.GL_TEXTURE_2D); 


////////////////////////////////////////////// 
// myRender 

GL11.glMatrixMode(GL11.GL_MODELVIEW); 
GL11.glLoadIdentity(); 
float trans = 0; 
GL11.glMatrixMode(GL11.GL_PROJECTION); 
GL11.glLoadIdentity(); 
// Origine en haut à gauche 
GLU.gluOrtho2D(0, width, height, 0); 
GL11.glViewport(0, 0, width, height); 
GL11.glDisable(GL11.GL_BLEND); 

GL11.glEnable(GL11.GL_TEXTURE_2D); 
GL11.glBindTexture(GL11.GL_TEXTURE_2D, idTexture.get(0)); 
GL11.glBegin(GL11.GL_QUADS); 
GL11.glNormal3f( 0.0f, 0.0f, 1.0f); 
GL11.glTexCoord2f(0.0f, 0.0f); 
GL11.glVertex2f(0, 0); 
GL11.glTexCoord2f(1.0f*rapWidth, 0.0f); 
GL11.glVertex2f(width, 0); 
GL11.glTexCoord2f(1.0f*rapWidth, 1.0f*rapHeight); 
GL11.glVertex2f(width, height); 
GL11.glTexCoord2f(0.0f, 1.0f*rapHeight); 
GL11.glVertex2f(0, height); 
GL11.glEnd(); 
GL11.glDisable(GL11.GL_TEXTURE_2D); 



/// 
// GL11.glTexSubImage2D 
the aim is change texture with GL11.glTexSubImage2D


There are an error in my code, because my display (canvas) is black, no texture.
:(

Mr EEK

pdufranc, I replied to your post in the OpenGL forum.