GLGraphics model question
in
Contributed Library Questions
•
2 years ago
I'm a bit confused by something I've run into with the GLGraphics library that I was hoping someone could explain to me. I'm creating a height map in shaders using multiple images and can't seem to get it to work the same way it does in C++.
- import processing.opengl.*;
- import codeanticode.glgraphics.*;
- GLModel poly;
- GLTexture colorTex;
- GLTexture heightTex;
- GLSLShader shader;
- float angle;
- void setup()
- {
- size(1024, 512, GLConstants.GLGRAPHICS);
- colorTex = new GLTexture(this, "earth.jpg");
- heightTex = new GLTexture(this, "earthbumps.jpg");
- shader = new GLSLShader(this, "bump.vert", "bump.frag");
- createModel();
- }
- void draw()
- {
- GLGraphics renderer = (GLGraphics)g;
- renderer.beginGL();
- background(0);
- rotateX( float(mouseY)/200.0 );
- translate( 0, float(mouseY/2), -float(mouseY/2) );
- shader.start(); // Enabling shader.
- shader.setTexUniform("colormap", 0);
- shader.setTexUniform("bumpmap", 1);
- shader.setIntUniform("maxHeight", 100);
- renderer.model(poly);
- shader.stop(); // Disabling shader.
- renderer.endGL();
- }
- void createModel()
- {
- // Creating rectangle, texture and GLSL shader.
- poly = new GLModel(this, 4, QUADS, GLModel.STATIC);
- poly.beginUpdateVertices();
- poly.updateVertex(0, 0, 0, 0);
- poly.updateVertex(1, 1024, 0, 0);
- poly.updateVertex(2, 1024, 512, 0);
- poly.updateVertex(3, 0, 512, 0);
- poly.endUpdateVertices();
- // Enabling the use of texturing...
- poly.initTexures(2);
- poly.setTexture(0, colorTex);
- poly.setTexture(1, heightTex);
- // Setting the texture coordinates.
- poly.beginUpdateTexCoords(0);
- poly.updateTexCoord(0, 0, 0);
- poly.updateTexCoord(1, 1, 0);
- poly.updateTexCoord(2, 1, 1);
- poly.updateTexCoord(3, 0, 1);
- poly.endUpdateTexCoords();
- // Setting the texture coordinates.
- poly.beginUpdateTexCoords(1);
- poly.updateTexCoord(0, 0, 0);
- poly.updateTexCoord(1, 1, 0);
- poly.updateTexCoord(2, 1, 1);
- poly.updateTexCoord(3, 0, 1);
- poly.endUpdateTexCoords();
- // is this needed? how is it done?
- poly.initNormals();
- poly.beginUpdateNormals();
- poly.updateNormal(0, 0, 0, -1);
- poly.updateNormal(1, 0, 0, -1);
- poly.updateNormal(2, 0, 0, -1);
- poly.updateNormal(3, 0, 0, -1);
- poly.endUpdateNormals();
- }
vertex
- uniform sampler2D colormap;
- uniform sampler2D bumpmap;
- varying vec2 TexCoord;
- uniform float maxHeight;
- void main(void)
- {
- TexCoord = gl_MultiTexCoord0.st;
- vec4 bumpColor = texture2D(bumpmap, TexCoord);
- float df = 0.30*bumpColor.x + 0.59*bumpColor.y + 0.11*bumpColor.z;
- vec4 newVertexPos = vec4(gl_Normal * df * float(maxHeight), 0.0) + gl_Vertex;
- gl_Position = gl_ModelViewProjectionMatrix * newVertexPos;
- }
fragment
- uniform sampler2D colormap;
- uniform sampler2D bumpmap;
- varying vec2 TexCoord;
- void main(void) {
- gl_FragColor = texture2D(colormap, TexCoord);
- }
1