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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| public void render() { float shade; float texLeft = 0.0f; float texUp = 0.0f; float texDown = 0.0f; float red = 1.0f; float green = 1.0f; float blue = 1.0f; if(isDetailed && isTextured) { gl.disable(GL.BLEND); gl.activeTextureARB(GL.TEXTURE0_ARB); gl.enable(GL.TEXTURE_2D); TextureManager.getTextureManager().bind(textureId); gl.activeTextureARB( GL.TEXTURE1_ARB ); gl.texEnvi( GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, GL.COMBINE_ARB ); gl.texEnvi( GL.TEXTURE_ENV, GL.RGB_SCALE_ARB, 2 );
TextureManager.getTextureManager().bind(id); } else if(isTextured) { gl.enable(GL.TEXTURE_2D); TextureManager.getTextureManager().bind(textureId); }
for (int z = 0; z < terrainSize - 1; z++) { gl.begin(GL.TRIANGLE_STRIP);
if(isTextured) { texUp = (float)z/terrainSize; texDown = (float)(z+1)/terrainSize; } for (int x = 0; x < terrainSize - 1; x++) { if(isTextured && isDetailed) { texLeft = (float)x/terrainSize; gl.multiTexCoord2fARB( GL.TEXTURE0_ARB, texLeft, texUp ); gl.multiTexCoord2fARB( GL.TEXTURE1_ARB, texLeft*repeatDetailMap, texUp*repeatDetailMap ); }else if(isTextured) { texLeft = (float)x/terrainSize; gl.texCoord2f(texLeft, texUp); } if(isLighted) { shade = lightMap.getShade(x,z); red = shade * lightMap.getColor().x; green = shade * lightMap.getColor().y; blue = shade * lightMap.getColor().z; } else { shade = (float)heightData.getTrueHeightAtPoint(x, z); shade /= 255; red = shade; green = shade; blue = shade; } gl.color3f(red, green, blue);
gl.vertex3f(x, heightData.getScaledHeightAtPoint(x, z), z);
if(isLighted) { shade = lightMap.getShade(x,z+1); red = shade * lightMap.getColor().x; green = shade * lightMap.getColor().y; blue = shade * lightMap.getColor().z; } else { shade = (float)heightData.getTrueHeightAtPoint(x, z+1); shade /= 255; red = shade; green = shade; blue = shade; } gl.color3f(red, green, blue); if(isTextured && isDetailed) { gl.multiTexCoord2fARB( GL.TEXTURE0_ARB, texLeft, texDown ); gl.multiTexCoord2fARB( GL.TEXTURE1_ARB, texLeft*repeatDetailMap, texDown*repeatDetailMap ); }else if(isTextured) { gl.texCoord2f(texLeft, texDown); }
gl.vertex3f( x, heightData.getScaledHeightAtPoint(x, z + 1), z + 1); }
gl.end(); } if(isTextured && isDetailed) { gl.activeTextureARB( GL.TEXTURE1_ARB ); gl.disable( GL.TEXTURE_2D ); gl.bindTexture( GL.TEXTURE_2D, 0 ); gl.activeTextureARB( GL.TEXTURE0_ARB ); gl.disable( GL.TEXTURE_2D ); gl.bindTexture( GL.TEXTURE_2D, 0 ); }else if(isTextured) { gl.disable(GL.TEXTURE_2D); } } |