Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Particlesystem works on linux but not on windows on: 2011-05-06 11:08:32
No, they are included.
And under windows everything runs fine, but not the particlesystem (I draw a small model, too).
2  Game Development / Newbie & Debugging Questions / Re: Particlesystem works on linux but not on windows on: 2011-05-04 20:42:46
Does no one knows how to fix this problem?
3  Game Development / Newbie & Debugging Questions / Particlesystem works on linux but not on windows on: 2011-05-01 12: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;

/**
 * The Node class manages a world that is build of ObjectContainers.
 * @author penguin
 */

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 };

    /**
     * Initializes the node
     * @param theCamera The cameraclass you want to use.
     */

    public Node(ICamera theCamera)
    {
        theObjects = new ArrayList<ObjectContainer>();
        myCamera = theCamera;
    }

    /**
     * Initializes the node.
     */

    public Node()
    {
        theObjects = new ArrayList<ObjectContainer>();
        myCamera = null;
    }

    /**
     * Adds an ObjectContainer to the node.
     * @param toAdd ObjectContainer to add.
     */

    public void addObjectContainer(ObjectContainer toAdd)
    {
        theObjects.add(toAdd);
    }

    /**
     * Draws the Node.
     */

    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;

/**
 * The ObjectContainer class manages a world that is build of Objects.
 * @author penguin
 */

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 };

    /**
     * Initializes the Container
     * @param translation The translation of the container.
     */

    public ObjectContainer(Vector3f translation)
    {
        theObjects = new ArrayList<IObject>();
        theTranslation = translation;
        Rotation = new Vector3f(0,0,0);
    }

    /**
     * Adds a object that implements IObject to the container.
     * @param toAdd Object to add.
     */

    public void addObject(IObject toAdd)
    {
        theObjects.add(toAdd);
    }

    /**
     * Draws the container.
     */

    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);
        }
    }

    /**
     * Generates variables for the container.
     */

    private void genObject()
    {
        // What is here todo? :/
   }

    /**
     * Rotate the container in X-Axis
     * @param angle Angle to rotate.
     */

    public void rotateX(float angle)
    {
        Rotation.x = angle;
        genObject();
    }

    /**
     * Rotate the container in Y-Axis
     * @param angle Angle to rotate.
     */

    public void rotateY(float angle)
    {
        Rotation.y = angle;
        genObject();
    }

    /**
     * Rotate the container in Z-Axis
     * @param angle Angle to rotate.
     */

    public void rotateZ(float angle)
    {
        Rotation.z = angle;
        genObject();
    }

    /**
     * Enables lightning in the container.
     */

    public void enableLightning()
    {
        GL11.glEnable(GL11.GL_LIGHTING);
    }

    /**
     * Disables lightning in the container.
     */

    public void disableLightning()
    {
        GL11.glDisable(GL11.GL_LIGHTING);
    }

    /**
     * Sets ambient light in the container.
     * @param ambientLight Lightcolor variables.
     */

    public void setAmbientLight(float[] ambientLight)
    {
        GL11.glDisable(GL11.GL_LIGHT1); // Disable 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); // Enable Light1
   }

    /**
     * Sets diffuselight in container.
     * @param diffuseLight Lightning color.
     * @param lightPosition Position of the diffuselight.
     */

    public void setDiffuseLight(float[] diffuseLight, float[] lightPosition)
    {
        GL11.glDisable(GL11.GL_LIGHT1); // Disable 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); // Enable Light 1
   }

    /**
     * Enables fog in the container.
     * @param fogColor The color of the fog.
     * @param FogMode Mode to draw the fog.
     * @param start Z-Coordinate where the fog starts.
     * @param end Z-Coordinate where the fog ends.
     * @param density Fog density.
     */

    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);
    }

    /**
     * Disables 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;

/**
 * The particle emitter for the particle engine.
 * @author penguin
 */

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;
    }

    /**
     * ParticleEmitter constructor
     * @param Position Position of the emitter
     * @param MoveTo Particles move in axes (Vector3f)
     * @param color Particles color
     * @param lifetime Particle's lifetime
     * @param particles Number of particles
     * @param generateLifetime should lifetime get generated?
     * @param Repeat Repeat everytime from 0 or spawn particles anytime?
     */

    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();
        }
    }
    /**
     * Updates the particles.
     */

    public void Update()
    {
        for(int i = 0; i < Particles.length; i++)
        {
            Particles[i].Update();
            if(!Particles[i].isParticleAlive())
            {
                if(repeat)
                Particles[i] = createParticle();
            }
        }
    }
    /**
     * Creates a particle with the values given in the constructor.
     * @return A new particle.
     */

    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;//generator.nextFloat() % 10)-5) / 10 * V;
       //System.out.println("NEW " + " " + position.x + " " + position.y + " " + position.z + " " + angle + " " + V + " " + velocity.x + " " + velocity.y + " " + velocity.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);
    }
    /**
     * Draws the particles to the screen.
     */

    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();
    }
    /**
     * Tests if work for every particle is done.
     * @return True if the work is done, false if there are any particles alive.
     */

    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;

/**
 * Ice Engine particle class for the particle engine.
 * @author penguin
 */

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;

    /**
     * Particle constructor.
     * @param Lifetime Lifetime for the particle.
     * @param gravity Gravity for calculating positions.
     * @param Position Startposition.
     * @param Velocity Speed of the particles movement.
     * @param color Particle color.
     */

    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;
    }
    /**
     * Updates the particles position.
     */

    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;
            }
        }
    }
    /**
     * Draws the particle to the screen.
     */

    public void drawParticle()
    {
        if (alive)
        {
            GL11.glColor4f(myColor.getRed(), myColor.getGreen(), myColor.getBlue(),0);
            GL11.glVertex3f(position.x, position.y, position.z);
        }
         
    }
    /**
     * Checks if the particle is alive.
     * @return True if it is alive, false if not.
     */

    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 13: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;

/**
 *
 * @author penguin
 */

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;// * moveTo.x;
       velocity.y = (float)Math.cos(angle) * V;// * moveTo.y;
       velocity.z = (((float)Math.random() * 10) - 5) / 10 * V;// * moveTo.z;//generator.nextFloat() % 10)-5) / 10 * V;
       //System.out.println("NEW " + " " + position.x + " " + position.y + " " + position.z + " " + angle + " " + V + " " + velocity.x + " " + velocity.y + " " + velocity.z);
       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++)
        {
            //System.out.println("DRAW " + i + " - " + Particles[i].position.x + " - " + Particles[i].position.y + " - " + Particles[i].position.z + " - " + Particles[i].velocity.x + " - " + Particles[i].velocity.y + " - " + Particles[i].velocity.z + " - " + (System.currentTimeMillis() - Particles[i].startTime));
           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;

/**
 *
 * @author penguin
 */

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()
    {
        // Update Particle
       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()
    {
        /*
        GL11.glBegin(GL11.GL_TRIANGLE_STRIP);

        GL11.glColor3f(myColor.getRed(), myColor.getGreen(), myColor.getBlue());
        position.z = - 2.0f;
        GL11.glVertex3f(position.x+size, position.y+size, position.z);
        GL11.glVertex3f(position.x-size, position.y+size, position.z);
        GL11.glVertex3f(position.x+size, position.y-size, position.z);
        GL11.glVertex3f(position.x-size, position.y-size, position.z);

        GL11.glEnd();
        */

       
        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()) // Same as Display.isCloseRequested();
         {
              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(); // Same as Display.update();
         }


I hope someone can help me Smiley
5  Game Development / Newbie & Debugging Questions / Problem with OpenAL - WaveData NullPointer on: 2011-03-18 15: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;

/**
 *
 * @author penguin
 */

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"); // hell.wav exists in Project folder, also tried with absolute path, but don't work.
         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 13: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;

/**
 *
 * @author penguin
 */

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;

/**
 *
 * @author penguin
 */

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.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glLoadIdentity();*/

        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;

/**
 *
 * @author penguin
 */

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;

/**
 *
 * @author penguin
 */

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) {

          }
          // Render Simple Triangle
         initGL();

          //WorldObject myObject = new WorldObject();
         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));
          //myObject.addFigure(myTriangle);
         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.
7  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Why does Lightning not Work? on: 2011-03-13 20:34:13
Yes, you're right.
Thank you very much Smiley
8  Game Development / Newbie & Debugging Questions / [SOLVED] [LWJGL] Why does Lightning not Work? on: 2011-03-13 20: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;

/**
 *
 * @author penguin
 */

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()) {
          // Draw a Triangle :D

          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;
          // Exit-Key = ESC
         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 };  // Ambient Light Values
       float lightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };      // Diffuse Light Values
       float lightPosition[] = { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position

        ByteBuffer temp = ByteBuffer.allocateDirect(16);
        temp.order(ByteOrder.nativeOrder());
        GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(lightAmbient).flip());              // Setup The Ambient Light
       GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(lightDiffuse).flip());              // Setup The Diffuse Light
       GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION,(FloatBuffer)temp.asFloatBuffer().put(lightPosition).flip());         // Position The Light
       GL11.glEnable(GL11.GL_LIGHT1);                          // Enable Light One
 }
}


Now, can someone here help me to get this work?

Thanks,
Penguin
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (29 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (79 views)
2014-09-10 06:39:09

Tekkerue (39 views)
2014-09-09 02:24:56

mitcheeb (58 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (36 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!