Mapping several Textures on the same surface

Hi,

I am rendering a cylinder and mapping two different textures to the top and to the bottom face.

Both the textures are loaded in the following way:

check3dFloorFile = new File(check3dFloorPath);
        
        try {
            check3dFloorTexture = TextureIO.newTexture(check3dFloorFile, true);
        } catch (IOException | GLException ex) {
            Logger.getLogger(Viewer.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        check3dFloorTexture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, 
                                                    GL2.GL_LINEAR_MIPMAP_LINEAR);
        check3dFloorTexture.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
                
        check3dFloorBackFile = new File(check3dFloorBackPath);
        
        try {
            check3dFloorBackTexture = TextureIO.newTexture(check3dFloorBackFile, true);
        } catch (IOException | GLException ex) {
            Logger.getLogger(Viewer.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        check3dFloorBackTexture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, 
                                                    GL2.GL_LINEAR_MIPMAP_LINEAR);
        check3dFloorBackTexture.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);

The problem arises when I try to render to a texture (a blank one, that has nothing to do with this first two ones):

gl.glGenTextures(1, textureID, 0);
        gl.glBindTexture(GL2.GL_TEXTURE_2D, textureID[0]);
        
        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
        
        // null means reserve texture memory, but texels are undefined
        gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_RGB, floorWidth, floorHeight,
                                                    0, GL2.GL_RGB, GL2.GL_FLOAT, null);
        
        gl.glGenFramebuffers(1, frameBufferID, 0);
        gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, frameBufferID[0]);
        
        //Attach 2D texture to this FBO
        gl.glFramebufferTexture2D(GL2.GL_FRAMEBUFFER, GL2.GL_COLOR_ATTACHMENT0, 
                                        GL2.GL_TEXTURE_2D, textureID[0], 0);
        
        // depth buffer
        //int[] depthRenderBufferID = new int[1];
        gl.glGenRenderbuffers(1, depthRenderBufferID, 0);
        gl.glBindRenderbuffer(GL2.GL_RENDERBUFFER, depthRenderBufferID[0]);
        gl.glRenderbufferStorage(GL2.GL_RENDERBUFFER, GL2.GL_DEPTH_COMPONENT, 
                                                floorWidth, floorHeight);
        gl.glFramebufferRenderbuffer(GL2.GL_FRAMEBUFFER, GL2.GL_DEPTH_ATTACHMENT,
                                            GL2.GL_RENDERBUFFER, depthRenderBufferID[0]);
        
        if(gl.glCheckFramebufferStatus(GL2.GL_FRAMEBUFFER) == GL2.GL_FRAMEBUFFER_COMPLETE)
            System.out.println("[Viewer] GL_FRAMEBUFFER_COMPLETE!!");
        else
            System.out.println("..cazzo ^^");

As soon as this code is executed, the texture mapped on the top of the cylinder disappears and all the top turns to black…

Why?

Ps: my task is to map this third rendered texture on the top of the cylinder, over the already existing one…

Why not simply using multitexturing?

You should rather post your questions on the official JogAmp forum too if you want more replies and I cannot come here by using a machine with a restricted web access, you see what I mean :wink:

Just use multi-texturing. IMO it’s easier to do it in a shader than by messing around with texture parameters.

I guess shader means OpenGL 3 or above… Im using 2.0

You can use shaders in OpenGL 2.0 too.

Do you have a link to any good guide/howto/tutorial?

Shaders were promoted to core in OpenGL 2.0… >_>

Hey comon, im a nub :smiley:

Otherwise I would not be here asking for your help :wink:

Well, sorry… :wink:

OpenGL 2 = DirectX 9 hardware (2002)
OpenGL 3 = DirectX 10 hardware (2007)
OpenGL 4 = DirectX 11 hardware (2009)

On top of this we have extensions, so some cards may for example not support OpenGL 2 fully but still support shaders, and some OGL 2 cards may support Frame Buffer Objects even though it was only promoted to core in OGL 3.

Btw, it is possible to do it without shaders?

Yes, but it’s messy as hell. You’ll have to Google it, since I took a look at it once, threw up and went over to using shaders.