Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Mapping several Textures on the same surface  (Read 1717 times)
0 Members and 1 Guest are viewing this topic.
Offline elect

Junior Member





« Posted 2012-02-09 15:54:16 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
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):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
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..
Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #1 - Posted 2012-02-10 00:27:52 »

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

Offline theagentd
« Reply #2 - Posted 2012-02-10 10:50:59 »

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

Myomyomyo.
Games published by our own members! Check 'em out!
Try the Free Demo of Titan Attacks
Offline elect

Junior Member





« Reply #3 - Posted 2012-02-10 11:15:34 »

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
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 50
Projects: 15


★★★★★


« Reply #4 - Posted 2012-02-10 11:17:08 »

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.
Offline elect

Junior Member





« Reply #5 - Posted 2012-02-10 11:23:25 »

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?
Offline theagentd
« Reply #6 - Posted 2012-02-10 12:16:27 »

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

Myomyomyo.
Offline elect

Junior Member





« Reply #7 - Posted 2012-02-10 14:14:14 »

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

Hey comon, im a nub Cheesy

Otherwise I would not be here asking for your help  Wink
Offline theagentd
« Reply #8 - Posted 2012-02-10 15:47:12 »

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

Hey comon, im a nub Cheesy

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.

Myomyomyo.
Offline elect

Junior Member





« Reply #9 - Posted 2012-02-17 15:25:20 »

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.

Btw, it is possible to do it without shaders?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #10 - Posted 2012-02-17 21:15:39 »

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.

Myomyomyo.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (107 views)
2013-05-17 21:29:12

alaslipknot (115 views)
2013-05-16 21:24:48

gouessej (144 views)
2013-05-16 00:53:38

gouessej (140 views)
2013-05-16 00:17:58

theagentd (152 views)
2013-05-15 15:01:13

theagentd (136 views)
2013-05-15 15:00:54

StreetDoggy (180 views)
2013-05-14 15:56:26

kutucuk (203 views)
2013-05-12 17:10:36

kutucuk (204 views)
2013-05-12 15:36:09

UnluckyDevil (210 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.207 seconds with 22 queries.