Show Posts
|
|
Pages: [1]
|
|
3
|
Game Development / Newbie & Debugging Questions / Particlesystem works on linux but not on windows
|
on: 2011-05-01 14:46:34
|
Hello, I wrote a little 3D Engine with a particlesystem, but there is a problem. Under Linux it runs fine, particle system works and other objects get displayed correct. But under Windows the particlesystem and two lines drawn in the same function that i added for debugging does not get drawn. Other objects get drawn correctly. I use the particle engine like this: Initialize ist, add it to a objectContainer and add the Container to a Node. Here are my Sources: Node.java 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
| package com.iceengine.j3d.container;
import java.util.ArrayList; import org.lwjgl.util.vector.Vector3f; import org.lwjgl.opengl.GL11;
import com.iceengine.j3d.camera.ICamera;
public class Node { private ArrayList<ObjectContainer> theObjects; private ICamera myCamera; int[] fogMode = {GL11.GL_EXP, GL11.GL_EXP2, GL11.GL_LINEAR };
public Node(ICamera theCamera) { theObjects = new ArrayList<ObjectContainer>(); myCamera = theCamera; }
public Node() { theObjects = new ArrayList<ObjectContainer>(); myCamera = null; }
public void addObjectContainer(ObjectContainer toAdd) { theObjects.add(toAdd); }
public void draw() { Vector3f translation = new Vector3f(0,0,0), rotation = new Vector3f(0,0,0); if(myCamera != null) { translation = myCamera.getTranslation(); rotation = myCamera.getRotation(); }
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); for(int i = 0; i < theObjects.size(); i++) {
theObjects.get(i).drawContainer(translation, rotation); } }
} |
ObjectContainer.java 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
| package com.iceengine.j3d.container;
import java.util.ArrayList; import com.iceengine.j3d.objects.*; import org.lwjgl.util.vector.Vector3f; import org.lwjgl.opengl.GL11;
import java.nio.FloatBuffer; import java.nio.ByteBuffer; import java.nio.ByteOrder;
public class ObjectContainer { private ArrayList<IObject> theObjects; private Vector3f theTranslation; private Vector3f Rotation; int[] fogMode = {GL11.GL_EXP, GL11.GL_EXP2, GL11.GL_LINEAR };
public ObjectContainer(Vector3f translation) { theObjects = new ArrayList<IObject>(); theTranslation = translation; Rotation = new Vector3f(0,0,0); }
public void addObject(IObject toAdd) { theObjects.add(toAdd); }
public void drawContainer(Vector3f Translation, Vector3f rotation) { Vector3f translation = theTranslation; Vector3f theRotation = Rotation;
translation = new Vector3f(theTranslation.x+Translation.x,theTranslation.y+Translation.y,theTranslation.z+Translation.z); theRotation = new Vector3f(Rotation.x+rotation.x,Rotation.y+(360.0f - rotation.y),Rotation.z+rotation.z);
for(int i = 0; i < theObjects.size(); i++) { theObjects.get(i).drawObject(translation, theRotation); } }
private void genObject() { }
public void rotateX(float angle) { Rotation.x = angle; genObject(); }
public void rotateY(float angle) { Rotation.y = angle; genObject(); }
public void rotateZ(float angle) { Rotation.z = angle; genObject(); }
public void enableLightning() { GL11.glEnable(GL11.GL_LIGHTING); }
public void disableLightning() { GL11.glDisable(GL11.GL_LIGHTING); }
public void setAmbientLight(float[] ambientLight) { GL11.glDisable(GL11.GL_LIGHT1); ByteBuffer temp = ByteBuffer.allocateDirect(16); temp.order(ByteOrder.nativeOrder()); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(ambientLight).flip()); GL11.glEnable(GL11.GL_LIGHT1); }
public void setDiffuseLight(float[] diffuseLight, float[] lightPosition) { GL11.glDisable(GL11.GL_LIGHT1); ByteBuffer temp = ByteBuffer.allocateDirect(16); temp.order(ByteOrder.nativeOrder()); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(diffuseLight).flip()); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION,(FloatBuffer)temp.asFloatBuffer().put(lightPosition).flip()); GL11.glEnable(GL11.GL_LIGHT1); }
public void enableFog(float fogColor, int FogMode, float start, float end, float density) { GL11.glClearColor(0.5f,0.5f,0.5f,1.0f); GL11.glFogi(GL11.GL_FOG_MODE, fogMode[FogMode]); GL11.glFogf(GL11.GL_FOG_COLOR, fogColor); GL11.glFogf(GL11.GL_FOG_DENSITY, density); GL11.glHint(GL11.GL_FOG_HINT, GL11.GL_NICEST); GL11.glFogf(GL11.GL_FOG_START, start); GL11.glFogf(GL11.GL_FOG_END, end); GL11.glEnable(GL11.GL_FOG); }
public void disableFog() { GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1.0f); GL11.glDisable(GL11.GL_FOG); } } |
ParticleEmitter.java 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
| package com.iceengine.j3d.particles;
import org.lwjgl.util.vector.Vector3f; import org.lwjgl.util.Color; import org.lwjgl.opengl.GL11;
import java.util.Random;
import com.iceengine.j3d.objects.IObject;
public class ParticleEmitter implements IObject{ private Vector3f position; private Vector3f Rotation; private Vector3f Gravitation; private int particleLifetime; private Color myColor; private Particle[] Particles; private Vector3f moveTo; private boolean GenerateLifetime; private boolean repeat;
public void drawObject(Vector3f theTranslation, Vector3f rotation) { Update(); drawParticles(); }
public void rotateX(float angle) { Rotation.x = angle; }
public void rotateY(float angle) { Rotation.y = angle; }
public void rotateZ(float angle) { Rotation.z = angle; }
public ParticleEmitter(Vector3f Position,Vector3f MoveTo,Vector3f gravitation, Color color, int lifetime, int particles, boolean generateLifetime, boolean Repeat) { Gravitation = gravitation; repeat = Repeat; GenerateLifetime = generateLifetime; moveTo = MoveTo; position = Position; myColor = color; particleLifetime = lifetime;
Rotation = new Vector3f(0,0,0);
Particles = new Particle[particles];
Random generator = new Random();
for(int i = 0; i < particles; i++) { Particles[i] = createParticle(); } } public void Update() { for(int i = 0; i < Particles.length; i++) { Particles[i].Update(); if(!Particles[i].isParticleAlive()) { if(repeat) Particles[i] = createParticle(); } } } private Particle createParticle() { float V = (float)(Math.random() * 25); float angle = (float)(Math.random() * 360); Vector3f velocity = new Vector3f();
velocity.x = (float)Math.sin(angle) * V * moveTo.x; velocity.y = (float)Math.cos(angle) * V * moveTo.y; velocity.z = (((float)Math.random() * 10) - 5) / 10 * V * moveTo.z; int life = 0; if(GenerateLifetime) { life = (int)(Math.random() * particleLifetime); } else { life = particleLifetime; }
return new Particle(life,new Vector3f(Gravitation.x, Gravitation.y, Gravitation.z), new Vector3f(position.x, position.y, position.z),velocity, myColor); } public void drawParticles() { GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glBegin(GL11.GL_POINT);
for(int i = 0; i < Particles.length; i++) { Particles[i].drawParticle(); } GL11.glEnd(); GL11.glBegin(GL11.GL_LINE); GL11.glVertex3f(1.0f,0.5f,10f); GL11.glVertex3f(1.0f, 1.0f, 10.0f); GL11.glEnd(); GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glColor4f(1,1,1,1);
GL11.glBegin(GL11.GL_LINE); GL11.glVertex3f(0.0f,0.5f,10f); GL11.glVertex3f(1.0f, 0.5f, 10.0f); GL11.glEnd(); } public boolean isWorkDone() { boolean workDone = false; for(int i = 0; i < Particles.length; i++) { if(!Particles[i].isParticleAlive()) workDone = true; } return workDone; } } |
Particle.java 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
| package com.iceengine.j3d.particles;
import org.lwjgl.util.vector.Vector3f; import org.lwjgl.util.Color; import org.lwjgl.opengl.GL11; public class Particle { private Vector3f position; private Vector3f velocity; private Vector3f Gravitation; private Color myColor; private int lifetime; public long startTime; private boolean alive;
public Particle(int Lifetime,Vector3f gravity, Vector3f Position, Vector3f Velocity, Color color) { Gravitation = gravity; position = Position; lifetime = Lifetime; myColor = color; velocity = Velocity;
startTime = System.currentTimeMillis();
alive = true; } public void Update() { if(alive) { if((System.currentTimeMillis() - startTime) <= lifetime) { position.x += velocity.x / 250; position.y += velocity.y / 250; position.z += velocity.z / 250;
velocity.x *= 0.975f; velocity.y *= 0.975f; velocity.z *= 0.975f;
velocity.x += Gravitation.x; velocity.y += Gravitation.y; velocity.z += Gravitation.z; } else { alive = false; } } } public void drawParticle() { if (alive) { GL11.glColor4f(myColor.getRed(), myColor.getGreen(), myColor.getBlue(),0); GL11.glVertex3f(position.x, position.y, position.z); } } public boolean isParticleAlive() { return alive; } } |
OpenGL init 1 2 3 4 5 6 7 8 9 10 11 12 13
| GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GLU.gluPerspective(45.0f,((float)Width)/((float)Height),0.1f,100.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glClearStencil(0); GL11.glLoadIdentity();
GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1.0f); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); |
I really don't know whats wrong there, i've tried much things but nothing works. In the ParticleEmitter.drawObject() function nothing gets drawn. Are there any windows specific things to do? Hope someone can help me, Penguin
|
|
|
|
|
4
|
Game Development / Newbie & Debugging Questions / LWJGL doesn't draw my Particles
|
on: 2011-04-06 15:55:12
|
I've played a bit with particles and wrote my own particle system. I had it working and changed somethings and now it won't work anymore. I've searched a long time for the wrong code, but i didn't find anything. Here's my code: ParticleEmitter.java 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 107 108 109 110 111 112 113 114 115 116 117 118 119
| package com.iceengine.particles;
import org.lwjgl.util.vector.Vector3f; import org.lwjgl.util.Color; import java.util.Random; import org.lwjgl.opengl.GL11; import com.iceengine.j3d.objects.IObject;
public class ParticleEmitter implements IObject{ private Vector3f position; private Vector3f Rotation; private int particleLifetime; private Color myColor; private Particle[] Particles; private float size; private Vector3f moveTo; private boolean GenerateLifetime; private boolean repeat;
public void drawObject(Vector3f theTranslation, Vector3f rotation) { GL11.glTranslatef(theTranslation.x, theTranslation.y, theTranslation.z); GL11.glRotatef(rotation.x + Rotation.x, 1.0f, 0.0f, 0.0f); GL11.glRotatef(rotation.y + Rotation.y, 0.0f, 1.0f, 0.0f); GL11.glRotatef(rotation.z + Rotation.z, 0.0f, 0.0f, 1.0f);
Update(); drawParticles(); } public void rotateX(float angle) { Rotation.x = angle; } public void rotateY(float angle) { Rotation.y = angle; } public void rotateZ(float angle) { Rotation.z = angle; } public ParticleEmitter(Vector3f Position,Vector3f MoveTo, Color color, int lifetime, int particles, float Size, boolean generateLifetime, boolean Repeat) { repeat = Repeat; GenerateLifetime = generateLifetime; moveTo = MoveTo; size = Size; position = Position; myColor = color; particleLifetime = lifetime;
Rotation = new Vector3f(0,0,0);
Particles = new Particle[particles];
Random generator = new Random();
for(int i = 0; i < particles; i++) { Particles[i] = createParticle(); } } public void Update() { for(int i = 0; i < Particles.length; i++) { Particles[i].Update(); if(!Particles[i].isParticleAlive()) { if(repeat) Particles[i] = createParticle(); } } } private Particle createParticle() { float V = (float)(Math.random() * 25); float angle = (float)(Math.random() * 360); Vector3f velocity = new Vector3f();
velocity.x = (float)Math.sin(angle) * V; velocity.y = (float)Math.cos(angle) * V; velocity.z = (((float)Math.random() * 10) - 5) / 10 * V; int life = 0; if(GenerateLifetime) { life = (int)(Math.random() * particleLifetime); } else { life = particleLifetime; }
return new Particle(size,life, new Vector3f(position.x, position.y, position.z),velocity, myColor); } public void drawParticles() { for(int i = 0; i < Particles.length; i++) { Particles[i].drawParticle(); } }
public boolean isWorkDone() { boolean workDone = false; for(int i = 0; i < Particles.length; i++) { if(!Particles[i].isParticleAlive()) workDone = true; } return workDone; } } |
Particle.java 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
| package com.iceengine.particles;
import org.lwjgl.util.vector.Vector3f; import org.lwjgl.util.Color; import org.lwjgl.opengl.GL11;
public class Particle { public Vector3f position; private int lifetime; public Vector3f velocity; private Color myColor; public long startTime; private boolean alive; private float size; public Particle(float Size,int Lifetime, Vector3f Position, Vector3f Velocity, Color color) { size = Size; position = Position; lifetime = Lifetime; myColor = color; velocity = Velocity;
startTime = System.currentTimeMillis();
alive = true; }
public void Update() { if(alive) { if((System.currentTimeMillis() - startTime) <= lifetime) { position.x += velocity.x / 250; position.y += velocity.y / 250; position.z += velocity.z / 250;
velocity.x *= 0.975f; velocity.y *= 0.975f; velocity.z *= 0.975f; } else { alive = false; } } }
public void drawParticle() { if (alive) { GL11.glBegin(GL11.GL_POINT); GL11.glColor3f(myColor.getRed(), myColor.getGreen(), myColor.getBlue()); GL11.glVertex3f(position.x, position.y, position.z); System.out.println("drawParticle() - " + position); GL11.glEnd(); } } public boolean isParticleAlive() { return alive; } } |
Here's how i use the code: 1 2 3 4 5 6 7 8 9 10 11 12
| ParticleEmitter theEmitter = new ParticleEmitter(new Vector3f(0,0,0), new Vector3f(1,1,0), new org.lwjgl.util.Color(org.lwjgl.util.Color.WHITE), 4000, 100, 1.0f, true, true); while(!IceEngine.isEngineCloseRequested()) { org.lwjgl.opengl.GL11.glClear(org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT | org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT); org.lwjgl.opengl.GL11.glLoadIdentity();
theEmitter.Update(); theEmitter.drawParticles(); IceEngine.update(); } |
I hope someone can help me 
|
|
|
|
|
5
|
Game Development / Newbie & Debugging Questions / Problem with OpenAL - WaveData NullPointer
|
on: 2011-03-18 16:21:10
|
Hello, Today i've started to do some things with OpenAL and i want to load a Wave-File, but if i try to load one with the WaveData Class (org.lwjgl.util.WaveData) the returned WaveData Object is a NullPointer. Here's my code: 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
| package com.iceengine.audio.sound;
import org.lwjgl.util.WaveData; import org.lwjgl.openal.AL10; import org.lwjgl.openal.AL;
import java.nio.IntBuffer; import org.lwjgl.BufferUtils; public class WaveSound implements Sound { private WaveData myData; private IntBuffer alBuffer = BufferUtils.createIntBuffer(1); private IntBuffer alSource = BufferUtils.createIntBuffer(1);
public void setListener(float[] Position, float[] Velocity, float[] Orientation) { AL10.alListener3f(AL10.AL_POSITION, Position[0], Position[1], Position[2]); AL10.alListener3f(AL10.AL_VELOCITY, Velocity[0], Velocity[1], Velocity[2]); AL10.alListener3f(AL10.AL_ORIENTATION, Orientation[0], Orientation[1], Orientation[2]); } public void loadSound(String Path) { myData = WaveData.create(Path); AL10.alGenBuffers(alBuffer); System.out.println(alBuffer + " " + myData); System.out.println(alBuffer + " " + myData.format + " " + myData.data + " " + myData.samplerate); AL10.alBufferData(alBuffer.get(0), myData.format, myData.data, myData.samplerate); myData.dispose(); } public void genSources(float[] sourcePos, float[] sourceVelocity) { AL10.alGenSources(alSource); AL10.alSourcei(alSource.get(0), AL10.AL_BUFFER, alBuffer.get(0)); AL10.alSourcef(alSource.get(0), AL10.AL_PITCH, 1.0f); AL10.alSourcef(alSource.get(0), AL10.AL_GAIN, 1.0f); AL10.alSource3f(alSource.get(0), AL10.AL_POSITION, sourcePos[0], sourcePos[1], sourcePos[2]); AL10.alSource3f(alSource.get(0), AL10.AL_VELOCITY, sourceVelocity[0], sourceVelocity[1], sourceVelocity[2]); }
public void killSource() { AL10.alDeleteBuffers(alBuffer.get(0)); AL10.alDeleteSources(alSource.get(0)); }
public void init() { try { AL.create(); } catch (Exception e) {
} } public void startPlay() { AL10.alSourcePlay(alSource.get(0)); } public void stopPlay() { AL10.alSourcePause(alSource.get(0)); } public void haltPlay() { AL10.alSourceStop(alSource.get(0)); } } |
Here's the code how i use my class: 1 2 3 4 5 6 7
| WaveSound mySound = new WaveSound(); mySound.init(); float[] tmp = {0.0f, 0.0f, 0.0f}; mySound.setListener(tmp, tmp, tmp); mySound.loadSound("hell.wav"); mySound.genSources(tmp, tmp); mySound.startPlay(); |
I hope someone can help me and, btw sorry for my bad english (I'm German). Regards, Penguin
|
|
|
|
|
6
|
Game Development / Newbie & Debugging Questions / [SOLVED] [LWJGL] Trouble with Display Lists
|
on: 2011-03-15 14:30:08
|
Hi there, Today i've started with writing a little "engine" for drawing simple figures (triangles, quads, etc.). I use DisplayLists cause of the lower cpu usage, but now here is my problem: I generate the Objects in an own class, but if i draw them they don't appear. Here are the Sources: IFigure.java 1 2 3 4 5 6 7 8 9
| package com.engine.objects;
public interface IFigure { public int getObjectList(); } |
Triangle.java 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
| package com.engine.objects;
import org.lwjgl.opengl.GL11;
public class Triangle implements IFigure { private Vertex[] Vertices; private int DisplayList; public Triangle(Vertex p1, Vertex p2, Vertex p3) { Vertices = new Vertex[3]; Vertices[0] = p1; Vertices[1] = p2; Vertices[2] = p3; DisplayList = GL11.glGenLists(1); this.genObject(); }
private void genObject() { GL11.glNewList(DisplayList, GL11.GL_COMPILE);
GL11.glBegin(GL11.GL_TRIANGLES); for (int i = 0; i < Vertices.length; i++) { if(Vertices[i].isTextureAvailable()) Vertices[i].bindTexture();
GL11.glVertex3f(Vertices[i].getX(), Vertices[i].getY(), Vertices[i].getZ());
if(Vertices[i].isColorAvailable()) GL11.glColor3f(Vertices[i].getRed(), Vertices[i].getGreen(), Vertices[i].getBlue());
if(Vertices[i].isMappingAvailable() && Vertices[i].isTextureAvailable()) GL11.glTexCoord2f(Vertices[i].getU(), Vertices[i].getV()); GL11.glEnd(); GL11.glEndList(); } } public int getObjectList() { return DisplayList; } } |
Vertex.java 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
| package com.engine.objects;
import org.lwjgl.util.vector.Vector3f; import org.lwjgl.util.vector.Vector2f; import org.newdawn.slick.opengl.Texture;
public class Vertex { private Vector3f Coordinates; private Vector3f Color; private Vector2f MappingCoordinates; private Texture theTexture;
public Vertex(Vector3f coordinates, Vector3f color, Vector2f mappingcoordinates, Texture thetexture) { Coordinates = coordinates; Color = color; MappingCoordinates = mappingcoordinates; theTexture = thetexture; }
public boolean isColorAvailable() { if(Color != null) return true; else return false; } public boolean isMappingAvailable() { if(MappingCoordinates != null) return true; else return false; } public boolean isTextureAvailable() { if(theTexture != null) return true; else return false; }
public void bindTexture() { theTexture.bind(); }
public float getX() { return Coordinates.x; } public float getY() { return Coordinates.y; } public float getZ() { return Coordinates.z; } public float getU() { return MappingCoordinates.x; } public float getV() { return MappingCoordinates.y; } public float getRed() { return Color.x; } public float getGreen() { return Color.y; } public float getBlue() { return Color.z; } } |
EngineTest.java (MainClass) 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
| package com;
import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; import org.lwjgl.opengl.GL11; import java.nio.FloatBuffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; import org.lwjgl.util.glu.GLU; import com.engine.objects.*; import org.lwjgl.util.vector.Vector3f;
public class EngineTest { public static void main(String[] args) {
try { Display.setDisplayMode(new DisplayMode(800,600)); Display.create(); } catch (Exception e) {
} initGL();
Triangle myTriangle = new Triangle(new Vertex(new Vector3f(1.0f,2.0f,1.0f),null,null,null),new Vertex(new Vector3f(1.0f,-1.0f,1.0f),null,null,null),new Vertex(new Vector3f(-1.0f,-1.0f,1.0f),null,null,null)); while(!Display.isCloseRequested()) { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glLoadIdentity(); GL11.glTranslatef(0.0f,0.0f,-10.0f);
GL11.glCallList(myTriangle.getObjectList());
Display.update(); }
Display.destroy();
}
private static void initGL() { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GLU.gluPerspective(45.0f,((float)800)/((float)600),0.1f,100.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity();
GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1.0f); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); } } |
I'm new to OpenGL and hope someone can help me cause i don't know where the mistake can be.
|
|
|
|
|
8
|
Game Development / Newbie & Debugging Questions / [SOLVED] [LWJGL] Why does Lightning not Work?
|
on: 2011-03-13 21:22:48
|
Hello, Today i've tried to do some Lightning in my Simple 3D Pyramid. I've read the NeHe tutorials and searched with google, but every code for Lightning that i used doesn't work. Here is my SourceCode: 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| package com;
import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; import org.lwjgl.opengl.GL11; import org.newdawn.slick.opengl.Texture; import org.newdawn.slick.opengl.TextureLoader; import java.io.FileInputStream; import org.lwjgl.util.glu.*; import org.lwjgl.input.Keyboard;
import java.nio.FloatBuffer; import java.nio.ByteBuffer; import java.nio.ByteOrder;
public class main {
public static void main(String[] args) { try { Display.setDisplayMode(new DisplayMode(800,600)); Display.setTitle("3D Pyramid"); Display.create(); } catch(Exception e) { } initGL();
float rtri = 0.0f; Texture texture = null; try { texture = TextureLoader.getTexture("JPG", new FileInputStream("E:/Textur.jpg")); } catch (Exception ex) { ex.printStackTrace(); } while(!Display.isCloseRequested()) { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glLoadIdentity();
GL11.glTranslatef(0.0f,0.0f,-10.0f);
GL11.glRotatef(rtri, 0.0f, 1.0f, 0.0f);
texture.bind();
GL11.glBegin(GL11.GL_TRIANGLES);
GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f(0.0f, 1.0f,0.0f); GL11.glTexCoord2f(-1.0f,-1.0f); GL11.glVertex3f(-1.0f, -1.0f,1.0f); GL11.glTexCoord2f(1.0f, -1.0f); GL11.glVertex3f(1.0f, -1.0f,1.0f);
GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f( 0.0f, 1.0f, 0.0f); GL11.glTexCoord2f(-1.0f,-1.0f); GL11.glVertex3f( 1.0f,-1.0f, 1.0f); GL11.glTexCoord2f(1.0f, -1.0f); GL11.glVertex3f( 1.0f,-1.0f, -1.0f);
GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f( 0.0f, 1.0f, 0.0f); GL11.glTexCoord2f(-1.0f,-1.0f); GL11.glVertex3f(-1.0f,-1.0f, -1.0f); GL11.glTexCoord2f(1.0f, -1.0f); GL11.glVertex3f( 1.0f,-1.0f, -1.0f);
GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f(0.0f, 1.0f,0.0f); GL11.glTexCoord2f(-1.0f,-1.0f); GL11.glVertex3f(-1.0f, -1.0f,-1.0f); GL11.glTexCoord2f(1.0f, -1.0f); GL11.glVertex3f(-1.0f, -1.0f,1.0f);
GL11.glEnd();
GL11.glBegin(GL11.GL_QUADS); GL11.glVertex3f( 1.0f,-1.0f, 1.0f); GL11.glVertex3f( 1.0f,-1.0f, -1.0f); GL11.glVertex3f(-1.0f,-1.0f, -1.0f); GL11.glVertex3f(-1.0f,-1.0f, 1.0f); GL11.glEnd();
Display.update(); rtri += 0.5f; boolean exitPressed = Keyboard.isKeyDown(Keyboard.KEY_ESCAPE); if(exitPressed) { System.out.println("Escape was pressed!"); Display.destroy();
} }
Display.destroy(); }
private static void initGL() { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GLU.gluPerspective(45.0f,((float)800)/((float)600),0.1f,100.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity();
GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1.0f); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); float lightAmbient[] = { 0.5f, 0.5f, 0.5f, 1.0f }; float lightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; float lightPosition[] = { 0.0f, 0.0f, 2.0f, 1.0f }; ByteBuffer temp = ByteBuffer.allocateDirect(16); temp.order(ByteOrder.nativeOrder()); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(lightAmbient).flip()); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(lightDiffuse).flip()); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION,(FloatBuffer)temp.asFloatBuffer().put(lightPosition).flip()); GL11.glEnable(GL11.GL_LIGHT1); } } |
Now, can someone here help me to get this work? Thanks, Penguin
|
|
|
|
|