Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Shaders and JOGL  (Read 1927 times)
0 Members and 2 Guests are viewing this topic.
Offline a6767

JGO n00b
*

Posts: 39



« on: 2007-08-01 16:14:51 »

I'm implementing shaders with glsl in my JOGL applet. Everything works fine, except textures. If I try to access to texture 1 (With MultiTexture activated) , my program access to texture 0. I pass the unit of texture as a uniform to texture2D function. There is no way to say to my fragment shader which texture I need to view.

The fragment shader is very simple:

uniform sampler2D colorMap;
uniform sampler2D envMap;
void main()
{
  vec4 color = texture2D(colorMap,gl_TexCoord[0].st);
  vec4 env = texture2D(envMap,gl_TexCoord[1].st);
  gl_FragColor=color+env*0.4;
}

It gets colorMap=0, envMap=0 . I believe this, because it applies as colorMap texture0 and as envMap texture0
Offline a6767

JGO n00b
*

Posts: 39



« Reply #1 on: 2007-08-01 16:42:06 »

I answer myself. Before calling glUniform you must call glActiveProgram
Offline gouessej

JGO Kernel
*****

Posts: 3560
Medals: 30


TUER


« Reply #2 on: 2007-08-03 07:29:21 »

Could you give me an example of shader to handle Phong model with textures please?

Julien Gouesse
Games published by our own members! Go get 'em!
Offline lhkbob

JGO Neuromancer
****

Posts: 1174
Medals: 35



« Reply #3 on: 2007-08-03 10:09:53 »

It shouldn't be that hard to find a Phong implementation on the web and just add some texturing support.  I would think all you need to do is calculate the phong lighting from before and then modulate it with the textures.

Offline a6767

JGO n00b
*

Posts: 39



« Reply #4 on: 2007-08-06 02:39:13 »

gouessej, I haven't one. But there are many samples in the web. In any case, it is not hard to implement one.

Take a look at these tuts

http://www.lighthouse3d.com/opengl/glsl/index.php?ogldir2

http://www.ozone3d.net/tutorials/glsl_lighting_phong.php
Offline gouessej

JGO Kernel
*****

Posts: 3560
Medals: 30


TUER


« Reply #5 on: 2007-08-08 07:34:37 »

gouessej, I haven't one. But there are many samples in the web. In any case, it is not hard to implement one.

Take a look at these tuts

http://www.lighthouse3d.com/opengl/glsl/index.php?ogldir2

http://www.ozone3d.net/tutorials/glsl_lighting_phong.php

Thanks but the main difficulty is to adapt it to handle the textures.

Julien Gouesse
Offline trbabb

JGO n00b
*

Posts: 4



« Reply #6 on: 2007-08-08 17:32:02 »

So, the lambertian term should be between 0 and 1. Multiply that value by the R, G, B sample you get from the texture. Then add the ambient to it. Then add the specular to it. Really, not difficult.
Offline gouessej

JGO Kernel
*****

Posts: 3560
Medals: 30


TUER


« Reply #7 on: 2007-08-13 07:43:04 »

So, the lambertian term should be between 0 and 1. Multiply that value by the R, G, B sample you get from the texture. Then add the ambient to it. Then add the specular to it. Really, not difficult.
Ok thank you very much. I'm a newbie in GLSL, sorry.

Julien Gouesse
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.097 seconds with 20 queries.