Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  Java Game APIs & Engines / OpenGL Development / Re: M3DMatrix44f in LWJGL? on: 2013-01-20 01:47:56
I will test the class and see if I can get it working. Thank you.
2  Java Game APIs & Engines / OpenGL Development / Re: M3DMatrix44f in LWJGL? on: 2013-01-20 00:42:38
Here is some code in C++ that I am trying to port into java.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
// Called to draw scene
void RenderScene(void)
    {
    M3DMatrix44f   transformationMatrix;   // Storeage for rotation matrix
   static GLfloat yRot = 0.0f;         // Rotation angle for animation
   yRot += 0.5f;
       
    // Clear the window with current clearing color
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       
    // Build a rotation matrix
   m3dRotationMatrix44(transformationMatrix, m3dDegToRad(yRot), 0.0f, 1.0f, 0.0f);
    transformationMatrix[12] = 0.0f;
    transformationMatrix[13] = 0.0f;
    transformationMatrix[14] = -2.5f;
       
    DrawTorus(transformationMatrix);

    // Do the buffer Swap
   glutSwapBuffers();
    }


Just an example, I am not sure what m3dRotationMatrix and M3DMatrix44f are. Maybe this will help you figure out what they are for.

I am a OpenGL noobie btw.
3  Java Game APIs & Engines / OpenGL Development / Re: M3DMatrix44f in LWJGL? on: 2013-01-20 00:25:57
I have with no luck at all, that is why I came here. Hoping someone who has been in a similar situation may provide some info.
4  Java Game APIs & Engines / OpenGL Development / M3DMatrix44f in LWJGL? on: 2013-01-20 00:07:04
Is there a class or method similar to M3DMatrix44f in LWJGL?
5  Java Game APIs & Engines / OpenGL Development / Re: OpenGL not rendering properly on: 2013-01-19 16:38:46
Nevermind I figured it out. The problem is that I have both fEarthRot and fMoonRot declared and initialized in the renderScene() method which is in the game loop. So the value of both variables never increase. Dumb move on my part.

Thanks for all the help Cheesy.
6  Java Game APIs & Engines / OpenGL Development / Re: OpenGL not rendering properly on: 2013-01-19 06:03:10
Riven thank you so much, that actually works much better Grin.

Now onto rotation.
7  Java Game APIs & Engines / OpenGL Development / Re: OpenGL not rendering properly on: 2013-01-19 05:54:56
So i figured out why my Earth and Moon were not showing up  Grin, I need to add this to my ByteBuffer

1  
2  
3  
4  
    ByteBuffer bBuffer = ByteBuffer.allocateDirect(1024 + 128).order(ByteOrder.nativeOrder());
    FloatBuffer lightPos = bBuffer.asFloatBuffer();
    FloatBuffer whiteLight = bBuffer.asFloatBuffer();
    FloatBuffer sourceLight = bBuffer.asFloatBuffer();


I am not 100% sure why this is a requirement but I think what it does is it sets the order of the bytes either to little endian or big endian depending on your system.
I guess without this it may cause a mismatch with which order your system uses thus leading to no visual of the objects.

Now the last problem I need to solve is the rotation.
Anyone?
8  Java Game APIs & Engines / OpenGL Development / Re: OpenGL not rendering properly on: 2013-01-19 04:06:17
Tried disabling lighting but now my Sun is gone.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
// Light values and coordinates
  glEnable(GL_DEPTH_TEST);   // Hidden surface removal
  glFrontFace(GL_CCW);      // Counter clock-wise polygons face out
  glEnable(GL_CULL_FACE);      // Do not calculate inside of jet

   // Enable lighting
  glEnable(GL_LIGHTING);

   // Setup and enable light 0
  glLightModel(GL_LIGHT_MODEL_AMBIENT,whiteLight);
   glLight(GL_LIGHT0,GL_DIFFUSE,sourceLight);
   glLight(GL_LIGHT0,GL_POSITION,lightPos);
   glEnable(GL_LIGHT0);

   // Enable color tracking
  glEnable(GL_COLOR_MATERIAL);
   
   // Set Material properties to follow glColor values
  glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);


I commented the lighting code out and now I see the Earth and Moon but no rotation.
What am I doing wrong about the lighting and why is there no rotation?

This code is copied straight out of the book except for the FloatBuffer but thats how its done in java.
9  Java Game APIs & Engines / OpenGL Development / [SOLVED] OpenGL not rendering properly on: 2013-01-19 02:19:27
This code is straight from OpenGL Superbible 4th edition and I cant seem to get it to work in LWJGL.
Can someone please help me.

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  
import general.OGLStarter;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import org.lwjgl.opengl.Display;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
import org.lwjgl.util.glu.Sphere;

public class Solar extends OGLStarter {
    ByteBuffer bBuffer = ByteBuffer.allocateDirect(1024 + 128);
    FloatBuffer lightPos = bBuffer.asFloatBuffer();
    FloatBuffer whiteLight = bBuffer.asFloatBuffer();
    FloatBuffer sourceLight = bBuffer.asFloatBuffer();
   
    Sphere glSphere = new Sphere();
   
    public Solar() {
        // Lighting Values
       float light[] = { 0.0f, 0.0f, 0.0f, 1.0f };
        float  whiteLight2[] = { 0.2f, 0.2f, 0.2f, 1.0f };
        float  sourceLight2[] = { 0.8f, 0.8f, 0.8f, 1.0f };
       
        // Add lighing values to buffers
       lightPos.put(light);
        lightPos.flip();
        whiteLight.put(whiteLight2);
        whiteLight.flip();
        sourceLight.put(sourceLight2);
        sourceLight.flip();
       
    }
   
    // Called to draw scene
   public void renderScene() {
        // Earth and Moon angle of revolution
       float fMoonRot = 0.0f;
        float fEarthRot = 0.0f;

        // Clear the window with current clearing color
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Save the matrix state and do the rotations
       glMatrixMode(GL_MODELVIEW);
        glPushMatrix();

        // Translate the whole scene out and into view  
       glTranslatef(0.0f, 0.0f, -300.0f);  

        // Set material color, Red
       // Sun
       glDisable(GL_LIGHTING);
        glColor3ub((byte)255, (byte)255, (byte)0);
        glSphere.draw(15.0f, 30, 17);
        glEnable(GL_LIGHTING);

        // Move the light after we draw the sun!
       glLight(GL_LIGHT0,GL_POSITION,lightPos);

        // Rotate coordinate system
       glRotatef(fEarthRot, 0.0f, 1.0f, 0.0f);

        // Draw the Earth
       glColor3ub((byte)0,(byte)0,(byte)255);
        glTranslatef(105.0f,0.0f,0.0f);
        glSphere.draw(15.0f, 30, 17);


        // Rotate from Earth based coordinates and draw Moon
       glColor3ub((byte)200,(byte)200,(byte)200);
        glRotatef(fMoonRot,0.0f, 1.0f, 0.0f);
        glTranslatef(30.0f, 0.0f, 0.0f);
        fMoonRot+= 15.0f;
        if(fMoonRot > 360.0f)
                fMoonRot = 0.0f;

        glSphere.draw(6.0f, 30, 17);

        // Restore the matrix state
       glPopMatrix();   // Modelview matrix


        // Step earth orbit 5 degrees
       fEarthRot += 5.0f;
        if(fEarthRot > 360.0f)
                fEarthRot = 0.0f;

        // Show the image
       Display.update();
        Display.sync(10);
    }


    // This function does any needed initialization on the rendering
   // context.
   public void setupRC() {
   // Light values and coordinates
  glEnable(GL_DEPTH_TEST);   // Hidden surface removal
  glFrontFace(GL_CCW);      // Counter clock-wise polygons face out
  glEnable(GL_CULL_FACE);      // Do not calculate inside of jet

   // Enable lighting
  glEnable(GL_LIGHTING);

   // Setup and enable light 0
  glLightModel(GL_LIGHT_MODEL_AMBIENT,whiteLight);
   glLight(GL_LIGHT0,GL_DIFFUSE,sourceLight);
   glLight(GL_LIGHT0,GL_POSITION,lightPos);
   glEnable(GL_LIGHT0);

   // Enable color tracking
  glEnable(GL_COLOR_MATERIAL);
   
   // Set Material properties to follow glColor values
  glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

   // Black blue background
  glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
    }

    public void checkSize(int w, int h) {
        float fAspect;

        // Prevent a divide by zero
       if(h == 0)
            h = 1;

        // Set Viewport to window dimensions
       glViewport(0, 0, w, h);

        // Calculate aspect ratio of the window
       fAspect = (float)w/(float)h;

        // Set the perspective coordinate system
       glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        // field of view of 45 degrees, near and far planes 1.0 and 425
       gluPerspective(45.0f, fAspect, 1.0f, 425.0f);

        // Modelview matrix reset
       glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
   
    public static void main(String[] args) {
        new Solar().run();
    }
}


This program is a mini solar system of just the Sun, the Earth and the Moon.
The Sun is in the center of the screen while the earth rotates around the Sun, similarly the Moon rotate around the Earth.

The Output that I get is only the Sun. What am I doing wrong?
10  Java Game APIs & Engines / OpenGL Development / Re: Stencil buffer help on: 2013-01-15 02:08:30
Ya but how can I do this without extending GLProgram?
 Edit** What is the OpenGL command?
EDIT*** Nevermind i figuered it out. Thanks alot dude.
11  Java Game APIs & Engines / OpenGL Development / [SOLVED] Stencil buffer help on: 2013-01-15 01:47:44
Hey guys, I cant seem to get the stencil buffer working properly.
Here is the 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  
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  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chapter3;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import static org.lwjgl.opengl.GL11.*;

public class Stencil {
    // Square position and size variables
   private float x1;
    private float y1;
    private float rsize;
    // Step size in x and y directions
   // (number of pixels to move each time)
   private float xstep;
    private float ystep;
   
    // Clipping area variables
   private float clipWidth;
    private float clipHeight;
   
    public Stencil() {
        // Initialize variables
       x1 = 0.0f;
        y1 = 0.0f;
        rsize = 25;
        xstep = 1.0f;
        ystep = 1.0f;
       
        // Create window
       try {
            Display.setDisplayMode(new DisplayMode(800, 600));
            Display.setTitle("Stencil Animation");
            Display.create();
            Display.setResizable(true);
            Display.setVSyncEnabled(true);
        } catch (LWJGLException e) {
            e.printStackTrace();
        }
    }
   
    /*
     * Called to run the program
     */

    public void run() {
        while (!Display.isCloseRequested()) {
            setupRC();
            changeSize(Display.getWidth(), Display.getHeight());
            animate(Display.getWidth(), Display.getHeight());
            renderScene();
           
            // Update display
           Display.update();
           // Display.sync(60);
       }
       
        cleanUp();
    }
   
    /*
     * Called to draw scene
     */

    public void renderScene() {
        double dRadius = 0.1;   // Initial radius of spiral
       double dAngle;
       
        // Use 0 for clear stencil, enable stencil test
       glClearStencil(0);
        glEnable(GL_STENCIL_TEST);
       
        // Clear color and stencil buffer
       glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
       
        // All drawing commands fail the stencil test, and are not
       // drawn, but increment the value in the stencil buffer
       glStencilFunc(GL_NEVER, 0x0, 0x0);
        glStencilOp(GL_INCR, GL_INCR, GL_INCR);
       
        // Spiral pattern will create stencil pattern
       // Draw the spiral pattern with white lines. We
       // make the lines white to demonstrate that the
       // stencil function prevents them from being drawn
       glColor3f(1.0f, 1.0f, 1.0f);
        glBegin(GL_LINE_STRIP);
            for (dAngle = 0; dAngle < 400; dAngle += 0.1) {
                glVertex2d(dRadius * Math.cos(dAngle), dRadius * Math.sin(dAngle));
                dRadius *= 1.002;
            }
        glEnd();
       
        // Now, allow drawing, except where the stencil pattern is 0x1
       // and do not make any further changes to the stencil buffer
       glStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
       
        // Now draw red bouncing square
       // (x and y) are modified by a timer function
       glColor3f(1.0f, 0.0f, 0.0f);
        glRectf(x1, y1, x1 + rsize, y1 - rsize);
    }
   
    /*
     * Set up the rendering state
     */

    public void setupRC() {
        // Set clear color to blue
       glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
    }
   
    /*
     * Set up method to adjust window size
     */

    public void changeSize(int w, int h) {
        float nRange = 100.0f;
       
        // Prevent a divide by zero
       if (h == 0) {
            h = 1;
        }
       
        // Set Viewport to window dimensions
       glViewport(0, 0, w, h);
       
        // Reset coordinate system
       glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
       
        // Establish clipping volume (left, right, bottom, top, near, far)
       if (w <= h) {
            glOrtho(-nRange, nRange, -nRange * h / w, nRange * h / w,
                    -nRange, nRange);
            clipWidth = nRange;
            clipHeight = nRange * h / w;
        } else {
            glOrtho(-nRange * w / h, nRange * w / h, -nRange, nRange,
                    -nRange, nRange);
            clipWidth = nRange * w / h;
            clipHeight = nRange;
        }
       
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
   
    /*
     * Check window size and adjust x and y values
     * accordingly, animate square
     */

    public void animate(float windowWidth, float windowHeight) {  
        // Reverse direction when you reach left or right edge
       // of the screen
       if (x1 > clipWidth - rsize || x1 < -clipWidth) {
            xstep = -xstep;
        }
       
        // Reverse direction when you reach top or bottom edge
       if (y1 > clipHeight || y1 < -clipHeight + rsize) {
            ystep = -ystep;
        }
       
        animate();
       
        // Check bounds. This is in case the window is made
       // smaller while the rectangle is bouncing and the
       // rectangle suddenly finds itself outside the new
       // clipping volume
       if (x1 > (windowWidth - rsize + xstep)) {
            x1 = windowWidth - rsize - 1;
        } else if (x1 < -(windowWidth + xstep)) {
            x1 = -windowWidth - 1;
        }
       
        if (y1 > (windowHeight + ystep)) {
            y1 = windowHeight - 1;
        } else if (y1 < -(windowHeight - rsize + ystep)) {
            y1 = -windowHeight + rsize - 1;
        }
    }
   
    /*
     * Move the square around the screen
     */

    public void animate() {
        x1 += xstep;
        y1 += ystep;
    }
   
    /*
     * Clean up method used to destroy unused objects
     */

    public void cleanUp() {
        Display.destroy();
    }
   
    public static void main(String[] args) {
        new Stencil().run();
    }
}



Im learning OpenGL through the OpenGL Superbible book. This is an example of using stencil buffer but it doesnt work for me? What am i missing?
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.

pw (18 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!