Texturing issue

Hi,

I am wanting to project a movie onto a rectangle into a rectangle in 3D space. The code I found for playing movies is fine, the example of texturing works, but when I put them together they don’t seem to work. After trying to see what is going wrong, it looks like I am probably doing something wrong in the OpenGL code. So I tried reducing it to the most simple case and tried creating a blue texture, but I still get a white rectangle, as if the texture was not being applied:


    Buffer pixels = null;
    
    ByteBuffer byteBuffer = ByteBuffer.allocate(width * height * 3);
    
    for ( int row=0; row<heigh; row++ ) {
      for ( int col=0; col<width; col++ ) {
        byteBuffer.put((byte)0);
        byteBuffer.put((byte)0);
        byteBuffer.put((byte)0xFF);
      }      
    }
    
    byteBuffer.rewind();
    pixels = byteBuffer;
    
    gl.glGenTextures(3, textures,0); /* * */
    gl.glBindTexture(GL.GL_TEXTURE_2D, textures[0]);

    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
    
    gl.glTexImage2D(GL.GL_TEXTURE_2D,
            0,
            GL.GL_RGB,
            320,
            240,
            0,
            GL.GL_RGB,
            GL.GL_UNSIGNED_BYTE,
            pixels);              

Any ideas?

On a separate note is that I can load to textures, but sometimes when I give them different names they all seem to be using the same image.

Textures have to be power of 2 unless you use an extension. Use allocateDirect instead of allocate when createing the byteBuffer variable. Although I’m not sure if JOGL actaully requires direct buffers.

So do the dimensions ( X & Y ) have be 2^n or the total number of bytes?

Also, do you have any suggestions on how to get the next power of 2 number, given an arbitrary integer?

The dimensions have to be pow2. Here is a function that returns the next pow2:




	/**
	 * Rounds the value up to its nearest power of 2.
	 * @param value the value to round up.
	 * @return returns a value wich is greater or equal to value and is a power of 2.
	 */
	public static int roundUpPow2(int value) {
		int result = 1;
		while (result < value) { 
			result *= 2;
		}
		
		return result;	
	}


Thanks Tom for your help. Your solution is also faster than an alternative one I found on the net, that was implemented using logarithms.