Removed the NVidia dependent Grass.java test (as it didn't even work on nvidia because of resource loading problems, and because the org.lwjgl.test.opengl.shaders examples are superior anyway)

This commit is contained in:
Elias Naur 2004-08-05 20:29:04 +00:00
parent 250bbea979
commit 0baf3a81f2
3 changed files with 0 additions and 660 deletions

View File

@ -1,472 +0,0 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* $Id$
*
* Simple java test program.
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
package org.lwjgl.test.opengl;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.Random;
import org.lwjgl.BufferUtils;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.opengl.NVProgram;
import org.lwjgl.opengl.NVVertexProgram;
import org.lwjgl.opengl.glu.GLU;
public class Grass {
static class Aslod {
float angle;
float value;
float ripple;
float count;
}
private static boolean finished = false;
private static Random rand = new Random();
static {
try {
int mode = -1;
DisplayMode[] modes = Display.getAvailableDisplayModes();
for (int i = 0; i < modes.length; i++) {
if (modes[i].getWidth ()== 640
&& modes[i].getHeight() == 480
&& modes[i].getBitsPerPixel() >= 16) {
mode = i;
break;
}
}
if (mode == -1) {
System.out.println("did not find suitable mode");
} else {
System.out.println("Display mode: " + modes[mode]);
}
// For now let's just pick a mode we're certain to have
Display.setDisplayMode(modes[mode]);
System.out.println("Created display.");
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
static {
try {
Display.create();
Keyboard.create();
Keyboard.enableBuffer();
Mouse.create();
System.out.println("Created OpenGL.");
} catch (Exception e) {
System.err.println("Failed to create OpenGL due to " + e);
System.exit(1);
}
}
private static Aslod aslod = new Aslod();
private static int mesh;
private static int program_handle;
private static byte[] loadFile(String file) {
int next;
java.util.Vector bytes = new java.util.Vector();
try {
ClassLoader loader = Grass.class.getClassLoader();
InputStream stream = new BufferedInputStream(loader.getResourceAsStream(file));
while ((next = (stream.read())) != -1)
bytes.add(new Byte((byte) next));
stream.close();
byte[] result = new byte[bytes.size()];
for (int i = 0; i < result.length; i++)
result[i] = ((Byte) bytes.get(i)).byteValue();
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
System.out.println("Vertex program supported: " + GLContext.GL_NV_vertex_program);
IntBuffer int_buf = BufferUtils.createIntBuffer(1);
NVProgram.glGenProgramsNV(int_buf);
if (int_buf.get(0) == 0)
throw new RuntimeException("Could not allocate new vertex program id!");
program_handle = int_buf.get(0);
byte[] program = loadFile("cg_grass2.vp");
ByteBuffer program_buf = BufferUtils.createByteBuffer(program.length);
program_buf.order(ByteOrder.nativeOrder());
program_buf.put(program);
program_buf.flip();
NVProgram.glLoadProgramNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
program_handle,
program_buf);
/*GL11.glGetInteger(GL11.PROGRAM_ERROR_POSITION_NV, int_buf);
System.out.println("error position: " + int_buf.get(0));*/
genMesh();
float[] LightDiffuse = { 1.0f, 0.0f, 0.0f, 1.0f };
float[] LightPosition = { 1.0f, 1.0f, 1.0f, 0.0f };
FloatBuffer light_buf_f = BufferUtils.createFloatBuffer(4);
light_buf_f.put(LightDiffuse);
light_buf_f.flip();
GL11.glLight(
GL11.GL_LIGHT0,
GL11.GL_DIFFUSE,
light_buf_f);
light_buf_f.clear();
light_buf_f.put(LightPosition);
light_buf_f.flip();
GL11.glLight(
GL11.GL_LIGHT0,
GL11.GL_POSITION,
light_buf_f);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_BLEND);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GLU.gluPerspective(40.0f, 1.0f, 1.0f, 50.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GLU.gluLookAt(14.0f, 10.0f, -16.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
aslod.angle = 2.6179935f;
aslod.value = 0.2f;
aslod.ripple = 0.0f;
aslod.count = 0.0f;
while (!finished) {
if (Display.isCloseRequested()) {
finished = true;
} else if (Display.isVisible()) {
keyPoll();
float degree = (1.0f + (aslod.value * 20.0f)) * 0.01745329f;
degree *= (0.5 + myrand());
ptrAnimate(degree);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
//ptrDraw();
grsDraw();
}
Display.update();
}
Display.destroy();
}
private static float myrand() {
// returns a value between 0 and 1
return rand.nextFloat();
}
private static void genGrass(
float fFaceHeight,
float fFaceWidth,
float fX,
float fZ) {
int cFaces;
int numFaces;
float cWidth;
float fDecWidth, frndWidth, frndHeight;
float fRotate;
float fRigid;
numFaces = 5;
frndHeight =
fFaceHeight
+ ((fFaceHeight / 1.5f)
* (float) java.lang.Math.cos(
java.lang.Math.abs(rand.nextInt())));
frndWidth =
fFaceWidth
+ ((fFaceWidth / 4.0f)
* (float) java.lang.Math.cos(
java.lang.Math.abs(rand.nextInt())));
fDecWidth = frndWidth / 5.0f;
fRotate = myrand() * 3.1415f;
fRigid = ((fRigid = myrand()) < 0.2f) ? 0.2f : fRigid;
if (myrand() < 0.3)
GL11.glBegin(GL11.GL_LINE_STRIP);
else
GL11.glBegin(GL11.GL_QUAD_STRIP);
for (cFaces = 0; cFaces < numFaces; cFaces++) {
for (cWidth = frndWidth;
cWidth >= -frndWidth;
cWidth -= (frndWidth * 2.0f)) {
GL11.glColor4f(fX, fRigid, fZ, (float) cFaces / (float) numFaces);
GL11.glVertex3f(
(float) (((cFaces - 2) * 0.1f)
* java.lang.Math.cos(fRotate)
+ (cWidth) * java.lang.Math.sin(fRotate)),
cFaces * frndHeight,
- (float)
(((cFaces - 2) * 0.1f) * java.lang.Math.sin(fRotate)
+ (cWidth) * java.lang.Math.cos(fRotate)));
}
frndWidth -= fDecWidth;
}
GL11.glEnd();
}
private static void genMesh() {
float cI, cJ, fArea;
fArea = 20.0f;
mesh = GL11.glGenLists(1);
GL11.glNewList(mesh, GL11.GL_COMPILE);
for (cI = -fArea / 2; cI < fArea / 2; cI += 0.25f) {
for (cJ = -fArea / 2; cJ < fArea / 2; cJ += 0.25f) {
genGrass(0.5f, 0.1f, cI, cJ);
}
}
GL11.glEndList();
}
private static void grsDraw() {
GL11.glEnable(NVVertexProgram.GL_VERTEX_PROGRAM_NV);
NVProgram.glBindProgramNV(NVVertexProgram.GL_VERTEX_PROGRAM_NV, program_handle);
NVVertexProgram.glTrackMatrixNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
0,
NVVertexProgram.GL_MODELVIEW_PROJECTION_NV,
NVVertexProgram.GL_IDENTITY_NV);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
4,
0.0f,
0.0f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
5,
0.0f,
0.0f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
6,
1.763609f,
0.496495f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
7,
-0.943599f,
3.203737f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
8,
4.101107f,
0.943413f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
9,
-1.218603f,
6.259399f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
10,
7.214299f,
1.352961f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
11,
-1.540748f,
10.080958f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
12,
10.880035f,
1.759046f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
13,
-1.852705f,
14.468674f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
14,
14.292879f,
1.973329f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
15,
-1.973387f,
18.506531f,
0.0f,
0.0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
16,
(float) (java.lang.Math.sin(aslod.angle)
* (aslod.value + aslod.ripple)),
0.0f,
(float) (java.lang.Math.cos(aslod.angle)
* (aslod.value + aslod.ripple)),
0.0f);
NVVertexProgram.glProgramParameter4fNV(NVVertexProgram.GL_VERTEX_PROGRAM_NV, 17, 1.7f, 5f, 2f, 0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
18,
-0.0187293f,
0.074261f,
0.2121144f,
1.570729f);
NVVertexProgram.glProgramParameter4fNV(NVVertexProgram.GL_VERTEX_PROGRAM_NV, 20, 0f, 0.5f, 1f, 0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
21,
0.25f,
-9f,
0.75f,
0.1591549f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
22,
24.9808f,
-24.9808f,
-60.14581f,
60.14581f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
23,
85.45379f,
-85.45379f,
-64.93935f,
64.93935f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
24,
19.73921f,
-19.73921f,
-1f,
1f);
NVVertexProgram.glProgramParameter4fNV(NVVertexProgram.GL_VERTEX_PROGRAM_NV, 25, 0f, 4f, 0f, 0f);
NVVertexProgram.glProgramParameter4fNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
19,
1f,
3.141593f,
0.5f,
1f);
NVVertexProgram.glProgramParameter4fNV(NVVertexProgram.GL_VERTEX_PROGRAM_NV, 26, 0.7f, 0.4f, 0f, 0f);
GL11.glCallList(mesh);
GL11.glDisable(NVVertexProgram.GL_VERTEX_PROGRAM_NV);
}
private static void ptrAnimate(float degree) {
aslod.count += degree;
aslod.ripple = (float) (java.lang.Math.cos(aslod.count) / 80.0);
}
private static void keyPoll() {
for (int i = 0; i < Keyboard.getNumKeyboardEvents(); i++) {
Keyboard.next();
if (!Keyboard.getEventKeyState())
continue;
switch (Keyboard.getEventKey()) {
case Keyboard.KEY_A :
aslod.angle += 0.1;
break;
case Keyboard.KEY_D :
aslod.angle -= 0.1;
break;
case Keyboard.KEY_W :
aslod.value += (aslod.value >= 0.15) ? 0.0 : 0.0025;
break;
case Keyboard.KEY_S :
aslod.value -= (aslod.value <= 0.005) ? 0.0 : 0.0025;
break;
case Keyboard.KEY_ESCAPE :
finished = true;
break;
}
}
}
}

View File

@ -1,72 +0,0 @@
#pragma bind app2vert.position = ATTR0
#pragma bind app2vert.normal = ATTR2
#pragma bind app2vert.color = ATTR3
struct app2vert : application2vertex
{
float4 position; //in object space
float3 normal; //in object space
float4 color;
};
#pragma bind vert2frag.HPOS = HPOS
#pragma bind vert2frag.COL0 = COL0
struct vert2frag : vertex2fragment
{
float4 HPOS;
float4 COL0;
};
vert2frag main(app2vert IN,
uniform float4x4 ModelViewProj,
uniform float4 Stiff[12],
uniform float4 Load)
{
vert2frag OUT;
float4 position;
float3 normal;
float3 disloc;
float4 dif;
float index;
float teta;
float alpha;
alpha = IN.position.y / 1.7;
// matrix line index
index = IN.color.a * 5 * 2;
// straw stiffness (randomic)
Load = Load * IN.color.y;
disloc.x = IN.position.x + dot(Stiff[index].xy, Load.xz);
disloc.y = IN.position.y;
disloc.z = IN.position.z + dot(Stiff[index + 1].xy, Load.xz);
// find the normal
teta = acos(IN.position.y / length(disloc));
normal = IN.position.xyz - disloc.xyz;
normal.y = sin(teta) * length(disloc);
normal = normalize(normal);
position.x = disloc.x + IN.color.x;
position.y = disloc.y;
position.z = disloc.z + IN.color.z;
position.w = 1;
OUT.HPOS = mul(ModelViewProj, position);
// calculate diffuse lighting off the normal that was just calculated
float4 lightPos = float4(0,4,0,0);
float4 lightVec = normalize(lightPos - position);
float diffuseInten = dot(lightVec.xyz, normal);
diffuseInten = (diffuseInten < 0.5) ? 0.5 : diffuseInten;
OUT.COL0 = float4(IN.color.y * 0.7, 0.7, 0.4, alpha) * diffuseInten;
return OUT;
}

View File

@ -1,116 +0,0 @@
!!VP1.0
# NV_vertex_program generated by NVIDIA Cg compiler
# cgc version 1.5.0001, build date Sep 12 2002 15:49:58
# command line args: -profile vp20 cg_grass2.cg
# nv30vp backend compiling 'main' program
#vendor NVIDIA Corporation
#version 1.0.1
#profile vp20
#program main
#semantic main.ModelViewProj
#semantic main.Stiff
#semantic main.Load
#var float4 IN.position : $vin.ATTR0 : ATTR0 : 0 : 1
#var float3 IN.normal : $vin.ATTR2 : ATTR2 : 0 : 1
#var float4 IN.color : $vin.ATTR3 : ATTR3 : 0 : 1
#var float4x4 ModelViewProj : : c[0], 4 : 1 : 1
#var float4 Stiff[0] : : c[4] : 2 : 1
#var float4 Stiff[1] : : c[5] : 2 : 1
#var float4 Stiff[2] : : c[6] : 2 : 1
#var float4 Stiff[3] : : c[7] : 2 : 1
#var float4 Stiff[4] : : c[8] : 2 : 1
#var float4 Stiff[5] : : c[9] : 2 : 1
#var float4 Stiff[6] : : c[10] : 2 : 1
#var float4 Stiff[7] : : c[11] : 2 : 1
#var float4 Stiff[8] : : c[12] : 2 : 1
#var float4 Stiff[9] : : c[13] : 2 : 1
#var float4 Stiff[10] : : c[14] : 2 : 1
#var float4 Stiff[11] : : c[15] : 2 : 1
#var float4 Load : : c[16] : 3 : 1
#var float4 HPOS : $vout.HPOS : HPOS : -1 : 1
#var float4 COL0 : $vout.COL0 : COL0 : -1 : 1
#const c[17] = 1.7 5 2 0
#const c[18] = -0.0187293 0.074261 0.2121144 1.570729
#const c[20] = 0 0.5 1 0
#const c[21] = 0.25 -9 0.75 0.1591549
#const c[22] = 24.9808 -24.9808 -60.14581 60.14581
#const c[23] = 85.45379 -85.45379 -64.93935 64.93935
#const c[24] = 19.73921 -19.73921 -1 1
#const c[25] = 0 4 0 0
#const c[19] = 1 3.141593 0.5 1
#const c[26] = 0.7 0.4 0 0
MUL R2, c[16], v[3].y;
MUL R0, v[3].w, c[17].y;
MUL R1, R0.x, c[17].z;
ARL A0.x, R1.x;
MUL R0, c[A0.x + 4].xyxx, R2.xzxx;
ADD R0, R0.x, R0.y;
ADD R3.x, v[0].x, R0.x;
MOV R3.y, v[0].y;
MUL R0, c[A0.x + 5].xyxx, R2.xzxx;
ADD R0, R0.x, R0.y;
ADD R3.z, v[0].z, R0.x;
ADD R2.x, R3.x, v[3].x;
MOV R2.y, R3.y;
ADD R2.z, R3.z, v[3].z;
MOV R2.w, c[19].x;
DP4 R0.x, c[0], R2;
DP4 R0.y, c[1], R2;
DP4 R0.z, c[2], R2;
DP4 R0.w, c[3], R2;
MOV o[HPOS], R0;
ADD R1.xz, v[0].xyzx, -R3.xyzx;
DP3 R0, R3.xyzx, R3.xyzx;
RSQ R0, R0.x;
RCP R0, R0.x;
RCP R3, R0.x;
MUL R6, v[0].y, R3.x;
MAX R5, R6.x, -R6.x;
MAD R3, c[18].x, R5.x, c[18].y;
MAD R3, R3.x, R5.x, -c[18].z;
MAD R4, R3.x, R5.x, c[18].w;
ADD R3, c[19].x, -R5.x;
RSQ R3, R3.x;
RCP R3, R3.x;
MUL R5, R4.x, R3.x;
SLT R4, R6.x, c[17].w;
MUL R3, c[17].z, R4.x;
MUL R3, R3.x, R5.x;
ADD R3, R5.x, -R3.x;
MAD R3, R4.x, c[19].y, R3.x;
MAD R6, c[21].w, R3.x, -c[21].x;
EXP R6.y, R6.x;
ADD R3, c[20].xyzx, -R6.yyyy;
MUL R5, R3.xyzx, R3.xyzx;
SLT R4.x, R6.y, c[21].x;
SGE R3, R6.yyyy, c[21].yzyy;
MOV R4.yz, R3.xxyw;
DP3 R4.y, R4.xyzx, c[24].zwzz;
MAD R3, c[22].xyxx, R5.xyzx, c[22].zwzz;
MAD R3, R3.xyzx, R5.xyzx, c[23].xyxx;
MAD R3, R3.xyzx, R5.xyzx, c[23].zwzz;
MAD R3, R3.xyzx, R5.xyzx, c[24].xyxx;
MAD R3, R3.xyzx, R5.xyzx, c[24].zwzz;
DP3 R5.x, R3.xyzx, -R4.xyzx;
MUL R1.y, R5.x, R0.x;
DP3 R0, R1.xyzx, R1.xyzx;
RSQ R0, R0.x;
MUL R3, R0.x, R1.xyzx;
ADD R1, c[25], -R2;
DP4 R0, R1, R1;
RSQ R0, R0.x;
MUL R0, R0.x, R1;
DP3 R2, R0.xyzx, R3.xyzx;
SLT R1, R2.x, c[19].z;
ADD R0, c[19].w, -R1.x;
MUL R0, R0.x, R2.x;
MAD R2, R1.x, c[19].z, R0.x;
MUL R1.x, v[3].y, c[26].x;
MOV R1.y, c[26].x;
MOV R1.z, c[26].y;
RCP R0, c[17].x;
MUL R1.w, v[0].y, R0.x;
MUL o[COL0], R1, R2.x;
END
# 72 instructions
# End of program