Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (290)
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] 2 3 ... 6
1  Game Development / Game Play & Game Design / Re: Saving and reloading game state on: 2013-05-01 20:53:56
As far as I know Serializable is the best choice for save/load - I did some tests and it works perfectly in any case. Wink
2  Game Development / Game Mechanics / Re: making a random distribution algorithm on: 2013-04-30 20:22:00
I think you can make something like this (pseudocode):

1  
2  
3  
4  
5  
6  
Random random = new Random();

while (seeds<16) {
pit[random.nextInt(7)]++;
seeds++
}
3  Game Development / Newbie & Debugging Questions / Re: Can games like Super Meat Boy or Binding of Isaac be recreated with Java? on: 2013-04-26 09:21:25
Meat Boy was made in AS (Flash), so there shouldn't be any problem with writing this kind of games in Java. I think you can make game like this using LWJGL and proper game loop and logic.
4  Game Development / Newbie & Debugging Questions / Re: Can games like Super Meat Boy or Binding of Isaac be recreated with Java? on: 2013-04-26 08:48:17
In Java you can make every kind of games - from simple 2d platformer to complicated 3d strategy. Wink
5  Game Development / Newbie & Debugging Questions / Re: Saving/load system on: 2013-04-24 21:24:45
By system I mean way to save the whole game state - entities, settings and then load them from files.
6  Game Development / Newbie & Debugging Questions / Saving/load system on: 2013-04-24 21:17:39
Like in topic - do I have to make the whole save/load system from scratch for everything I want to save/load or is there any easier and faster way to handle this?
7  Game Development / Game Mechanics / Re: How to correctly align with a pixel perfect collision detection? on: 2013-04-13 18:01:52
If you are using OpenGL (LWJGL/JOGL) then you can use occlusion query. It gives only true or false, but this is enough in most cases.
8  Game Development / Newbie & Debugging Questions / Re: Is this code evil? on: 2013-04-13 12:48:49
If you want to make your game moddable then yes, this is evil. Otherwise, I would still use external files to store data like this - this does not have to be xml files, personally I use classic txt files formated like this:

1  
2  
Key=Value
Another_key=Another_value


Such files are really, really easy to write, modify and read.
9  Discussions / General Discussions / Re: why are people trying to use Java2D to make games? on: 2013-04-06 19:59:06
In my opinion Java2d is for quick development, prototyping, tile-based games and everything with mostly static graphics without advanced graphical effects.
10  Game Development / Game Mechanics / World generation questions on: 2013-04-02 21:37:11
As I can't find anything related to the world generation in Google (most of results are Minecraft-related) I have to ask few questions about world generation there:

1. What algorithms should I use to make 2d "world" map? (based on seed and world creation parameters)
2. Is it possible to make 3d map using the same seed, world creation parameters and data from world map without generating the whole map at start (generation after player will choose site, not during initial generation)? Each "chunk" must always look the same and seamlessly connect with another chunks regardless of choosen world chunks. Player can choose any chunks amount, like 1X1, 2X1, 3X2, 5X5. Little example below:

3. I want to add minerals into 3d map rocks - is it possible using specific algorithm (again, generation depending on seed and parameters - map using the same seed and parameters must be always the same)?

Thank you in advance for all replies.
11  Game Development / Game Mechanics / Multiple threads on: 2013-03-29 23:15:35
I wonder if multi-threaded game can be faster than single (or double) threaded game. What do you think, is using multiple threads for game logic good idea in projects in which the CPU performance is the most important?
12  Java Game APIs & Engines / OpenGL Development / Re: Spectator camera problem - y axis on: 2013-03-23 21:59:52
This is even worse - camera is "waving" up and down.
13  Java Game APIs & Engines / OpenGL Development / Spectator camera problem - y axis on: 2013-03-23 11:48:21
Like in topic. I want to make 3d camera for my tool, but I have problem with camera on y (up-down) axis. x and z axis camera works well, but when I look up and down camera is becoming less and less sensitive while trying to move camera straight up or straight down, up to infinity. I know what may be problem, but I don't have any idea how to fix this.

My camera 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  
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.util.glu.GLU;

public class Camera {
   
    private int pastMousex;
    private int pastMousey;
   
    private float fraction = 0.1f;
    private float rotate = 0.01f;
   
    private float posx=0;
    private float posy=0;
    private float posz=0;
   
    private float dirx=0;
    private float diry=0;
    private float dirz=-1;
   
    private float anglex=0;
    private float angley=0;
   
    public void setSpeed(float speed, float rotation) {
        fraction=speed;
        rotate=rotation;
    }
   
    public void update(KeyboardInput keyboard, MouseInput mouse) {
        if (mouse.pressed.left) {
            Mouse.setGrabbed(true);
            Mouse.setCursorPosition(Display.getWidth()/2, Display.getHeight()/2);
            pastMousex = Display.getWidth()/2;
            pastMousey = Display.getHeight()/2;
        }
        else if (mouse.hold.left) {
            float diffx = mouse.x - pastMousex;
            float diffy = mouse.y - pastMousey;
           
            angley += diffx*rotate;
            dirx = (float)Math.sin(angley);
            dirz = (float)-Math.cos(angley);
           
            anglex += diffy*rotate;
            diry = anglex;
           
            if (angley>Math.PI*2) {
                angley-=Math.PI*2;
            }
            else if (angley<0) {
                angley+=Math.PI*2;
            }
           
            Mouse.setCursorPosition(Display.getWidth()/2, Display.getHeight()/2);
            pastMousex = Display.getWidth()/2;
            pastMousey = Display.getHeight()/2;
        }
        else if (mouse.released.left) {
            mouse.setMouseGrabbed(false);
        }
        if (keyboard.hold.d) {
            posx += (float)Math.sin(angley+Math.PI/2)*fraction;
            posz += (float)-Math.cos(angley+Math.PI/2)*fraction;
        }
        if (keyboard.hold.a) {
            posx += (float)Math.sin(angley-Math.PI/2)*fraction;
            posz += (float)-Math.cos(angley-Math.PI/2)*fraction;
        }
        if (keyboard.hold.w) {
            posx += dirx * fraction;
            posz += dirz * fraction;
            posy += diry * fraction;
        }
        if (keyboard.hold.s) {
            posx -= dirx * fraction;
            posz -= dirz * fraction;
            posy -= diry * fraction;
        }
    }
   
    public void set() {
        GLU.gluLookAt(posx, posy, posz, posx+dirx, posy+diry, posz+dirz, 0, 1, 0);
    }
   
}
14  Game Development / Newbie & Debugging Questions / Re: LWJGL canvas in Swing app - resize problems on: 2013-03-12 18:25:55
Still the same problem. Here is my code:

HouseCalc applet:

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  
package Form;

import Mapper.Mapper;

public class HouseCalc extends javax.swing.JApplet {

    Mapper mapper;
   
    @Override
    public void init() {
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
       /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */

        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(HouseCalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(HouseCalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(HouseCalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(HouseCalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                    mapper = new Mapper();
                    mapper.run();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
   private void initComponents() {

        mainPane = new javax.swing.JPanel();
        interfacePane = new javax.swing.JPanel();
        programFrame = new java.awt.Canvas();

        mainPane.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                mainPaneComponentResized(evt);
            }
        });

        javax.swing.GroupLayout interfacePaneLayout = new javax.swing.GroupLayout(interfacePane);
        interfacePane.setLayout(interfacePaneLayout);
        interfacePaneLayout.setHorizontalGroup(
            interfacePaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 250, Short.MAX_VALUE)
        );
        interfacePaneLayout.setVerticalGroup(
            interfacePaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 600, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout mainPaneLayout = new javax.swing.GroupLayout(mainPane);
        mainPane.setLayout(mainPaneLayout);
        mainPaneLayout.setHorizontalGroup(
            mainPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPaneLayout.createSequentialGroup()
                .addComponent(interfacePane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(programFrame, javax.swing.GroupLayout.DEFAULT_SIZE, 540, Short.MAX_VALUE))
        );
        mainPaneLayout.setVerticalGroup(
            mainPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(interfacePane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(programFrame, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>

    private void mainPaneComponentResized(java.awt.event.ComponentEvent evt) {
        mapper.resizeRequest();
    }

    // Variables declaration - do not modify
   private javax.swing.JPanel interfacePane;
    private javax.swing.JPanel mainPane;
    public static java.awt.Canvas programFrame;
    // End of variables declaration
}


Mapper:

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  
package Mapper;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;

public class Mapper {
   
    protected GLUtils util;
   
    private boolean resizeRequested = false;
   
    public Mapper() {}
   
    public void run() {
        Thread engine = new Thread() {
            public void run() {
                util = new GLUtils();
                util.initDisplay();
                util.initOpenGL();
                loop();
            }
        };
        engine.start();
    }
   
    private void loop() {
        while (true) {
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
            resize();
            draw();
            Display.update();
            Display.sync(30);
        }
    }
   
    private void draw() {
        GL11.glBegin(GL11.GL_TRIANGLES);
            GL11.glVertex2f(0.1f, 0.1f);
            GL11.glVertex2f(0.1f, 0.5f);
            GL11.glVertex2f(0.5f, 0.5f);
        GL11.glEnd();
    }
   
    public void resizeRequest() {
        resizeRequested=true;
    }
   
    private void resize() {
        if (resizeRequested) {
            util.refit();
            resizeRequested=false;
        }
    }
   
}


GLUtils:

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  
package Mapper;

import Form.HouseCalc;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

public class GLUtils {
   
    protected GLUtils() {}
   
    protected void initDisplay() {
        try {
            HouseCalc.programFrame.setIgnoreRepaint(true);
            HouseCalc.programFrame.setFocusable(true);
            Display.setParent(HouseCalc.programFrame);
            Display.setVSyncEnabled(true);
            Display.setResizable(true);
            Display.create();
        } catch (LWJGLException ex) {
            Logger.getLogger(GLUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
   
    protected void initOpenGL() {
        GL11.glClearColor(0, 0, 0, 0);
        GL11.glViewport(0, 0, HouseCalc.programFrame.getWidth(), HouseCalc.programFrame.getHeight());
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GL11.glOrtho(0, 1, 0, 1, 1, -1);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
    }
   
    protected void refit() {
        GL11.glViewport(0, 0, HouseCalc.programFrame.getWidth(), HouseCalc.programFrame.getHeight());
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GL11.glOrtho(0, 1, 0, 1, 1, -1);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
    }
   
}


In theory, everything should work correctly, but it isn't.

EDIT: it seems that the cause is canvas. Can I fix it or replace with something else?
15  Game Development / Newbie & Debugging Questions / LWJGL canvas in Swing app - resize problems on: 2013-03-12 16:59:51
Like in topic. I am trying to embed LWJGL canvas into Swing app, but I am encountering problems. It seems that when you increase the size of applet window everything is resizing correctly, but when you are trying to shrink applet window canvas does not resize correctly (LWJGL Display still have the same size even if it is much bigger than program window). Is there anything I can do to fix this?
16  Discussions / General Discussions / Re: ShaderToy becomes a web-site on: 2013-03-05 17:53:14
Sadly the next thing that does not work in Opera, but... very useful site, anyway. I was waiting for a program that will allow me to write shaders without changes in code, it seems that this one is ideal for this. Smiley
17  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Translate a gun at a fixed position in the screen on: 2013-03-04 21:26:32
I am using another OpenGL versions, so my code probably will not tell you too much, but I can always help from the theoretical side. Wink

In short, you should:
-set your "standard" 3d rendering camera
-draw things like map, enemies etc.
-set contant 3d rendering camera
-draw 3d things which are always in the same place (gun)
-set constant 2d rendering camera
-draw 2d things which are always in the same place (interface)
18  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Translate a gun at a fixed position in the screen on: 2013-03-04 20:44:02
Sample rendering code from one of my prototypes. I am writing 2d games, but I think that this should look rather similar in 3d games:

1  
2  
3  
4  
5  
6  
        GCore.renderer.startDrawing(); //function which is initializing my rendering system
           GCore.renderer.setCamera(logic.ship.x, logic.ship.y); //set camera position to ship center - in your case also set perspective matrix.
           logic.ship.draw(); //draw ship
           GCore.renderer.setCamera(WIDTH/2, HEIGHT/2); //set "neutral" camera for drawing interface - in your case you should keep perspective matrix there, render your gun and then set ortho matrix and render 2d elements of interface
           logic.menu.draw(); //interface rendering
       GCore.renderer.endRendering();


By "neutral" I mean constant camera positions.
19  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Translate a gun at a fixed position in the screen on: 2013-03-04 20:07:46
I think that you should set camera position to "neutral" (like for interface rendering) and then render weapon - it will be fully independend from player rotation, position etc.
20  Java Game APIs & Engines / OpenGL Development / Re: Strange error - LWJGL game working on one computer but not on another on: 2013-03-02 23:24:55
It seems that I found error, I had to change this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
if (shader!=activeProgram) {
            GL20.glUseProgram(shader);
            projectionMatrixLocation = GL20.glGetUniformLocation(shader, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(shader, "viewMatrix");
            modelMatrixLocation = GL20.glGetUniformLocation(shader, "modelMatrix");
            if (in!=null) {
                for (int i=0; i<in.length; i++) {
                    in[i].location = GL20.glGetUniformLocation(shader, in[i].name);
                }
            }
            textureBeginID = GL20.glGetUniformLocation(shader, "beginTexture");
            textureTranslationsID = GL20.glGetUniformLocation(shader, "translateTexture");
            activeProgram = shader;
        }


into this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
if (shader!=activeProgram) {
            GL20.glUseProgram(shader);
            projectionMatrixLocation = GL20.glGetUniformLocation(shader, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(shader, "viewMatrix");
            modelMatrixLocation = GL20.glGetUniformLocation(shader, "modelMatrix");
            textureBeginID = GL20.glGetUniformLocation(shader, "beginTexture");
            textureTranslationsID = GL20.glGetUniformLocation(shader, "translateTexture");
            activeProgram = shader;
        }
       
        if (in!=null) {
            for (int i=0; i<in.length; i++) {
                in[i].location = GL20.glGetUniformLocation(shader, in[i].name);
            }
        }
21  Java Game APIs & Engines / OpenGL Development / Re: Strange error - LWJGL game working on one computer but not on another on: 2013-03-02 22:36:42
Just to be sure, has your second programmer made sure to use Linux natives, not Windows natives?

Naturally.

About the chain of methods: here it is, starting from Core.Core.main:

1  
2  
3  
    public static void main(String[] args) {
            new Core(); //<-this line
   }


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  
    public Core() {
        logic = new Logic();
        physics = new Physics();
        graphics = new Graphics();
        audio = new Audio();
        input = new In();
       
        logic.initialize();
        physics.initialize();
        graphics.initialize();
        audio.initialize();
        input.initialize();
       
        graphics.setLogic(logic);
       
        while(!Display.isCloseRequested()) {
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
           
            input.update();
            logic.update();
            physics.update();
            graphics.update(); //<-this line
           audio.update();
           
            Display.update();
            Display.sync(60);
        }
        Display.destroy();
    }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
    private int time = 0;
   
    public void update() {
        time++;
        GCore.renderer.startDrawing();
            logic.ship.draw(); //<-this line
           if (In.keyboard.hold.one) {
                GCore.renderer.render(TL.black, SL.postProcess, WIDTH/2, HEIGHT/2, WIDTH, HEIGHT, 0, new ShaderInput("time", time)); //this line is working even though it is using ShaderInput - its shader is using uniform float time.
           }
       
        GCore.renderer.endRendering();
        time%=60;
    }


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  
    public void draw() {
        //To kick from draw() - from there...
       float centerX = 0;
        float centerY = 0;
       
        int first = 10;
        int second = 6;
        boolean[][] shipArray = new boolean[first][second];
     
        for(int count = 0; count<first; count++){
            for(int countInside = 0; countInside<second; countInside++){
                shipArray[count][countInside] = true;
            }
        }
        //...to there
       
        for(int count = 0; count<first; count++){
            for(int countInside = 0; countInside<second; countInside++){
                if(shipArray[count][countInside]==true){
                    switch(countInside%2) {
                        case 0:
                            GCore.renderer.renderShift(TL.blankHex, SL.coloredShader, x, y, (scaleX*(count*2))-centerX, (scaleY*(countInside*1.5f))-centerY, scaleX, scaleY, rotate, new ShaderInput("color", 0, 1, 1, 1)); //<-this line
                           // /\ line above
                           break;
                        case 1:
                            GCore.renderer.renderShift(TL.blankHex, SL.coloredShader, x, y, (scaleX*(count*2)-scaleX)-centerX, (scaleY*(countInside*1.5f))-centerY, scaleX, scaleY, rotate, new ShaderInput("color", 0, 1, 1, 1));
                            break;
                    }
                   
                }
            }
        }
    }


And, the whole RendererEngine class:

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  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
package Lib.Graphics;

import Core.Graphics.Graphics;
import Lib.Graphics.Shaders.ShaderInput;
import Lib.Graphics.Textures.Tex;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;

public class RenderEngine {
   
    private int activeProgram = 0;
    private int activeTexture = 0;
   
    private int vaoId = 0;
    private int vboId = 0;
    private int vboiId = 0;
    private int indicesCount = 0;
    private Vertex[] vertices = null;
    private ByteBuffer verticesByteBuffer = null;
   
    private int textureBeginID = 0;
    private int textureTranslationsID = 0;
    private int projectionMatrixLocation = 0;
    private int viewMatrixLocation = 0;
    private int modelMatrixLocation = 0;
    private Matrix4f projectionMatrix = null;
    private Matrix4f viewMatrix = null;
    private Matrix4f modelMatrix = null;
    private Vector3f modelPos = null;
    private Vector3f modelShift = null;
    private Vector3f modelAngle = null;
    private Vector3f modelScale = null;
    private Vector3f cameraPos = null;
    private FloatBuffer matrix44Buffer = null;
   
    public RenderEngine() {}
   
    public void initialize(int width, int height) {
        setupMatrices(width, height);
        setupQuad();
    }
   
    public void startDrawing() {
        GL20.glUseProgram(activeProgram);
       
        GL30.glBindVertexArray(vaoId);
        GL20.glEnableVertexAttribArray(0);
        GL20.glEnableVertexAttribArray(1);
        GL20.glEnableVertexAttribArray(2);

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
       
        setCamera(0, 0);
    }
   
    public void render(Tex texture, int shader, float x, float y, float scalex, float scaley, ShaderInput...in) {
        render(texture, shader, x, y, scalex, scaley, 0, in);
    }
   
    public void render(Tex texture, int shader, float x, float y, float scalex, float scaley, float angle, ShaderInput...in) {
        x = (x*2)-Graphics.WIDTH;
        y = (y*2)-Graphics.HEIGHT;
        scalex*=2;
        scaley*=2;
        if (shader!=activeProgram) {
            GL20.glUseProgram(shader);
            projectionMatrixLocation = GL20.glGetUniformLocation(shader, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(shader, "viewMatrix");
            modelMatrixLocation = GL20.glGetUniformLocation(shader, "modelMatrix");
            if (in!=null) {
                for (int i=0; i<in.length; i++) {
                    in[i].location = GL20.glGetUniformLocation(shader, in[i].name);
                }
            }
            textureBeginID = GL20.glGetUniformLocation(shader, "beginTexture");
            textureTranslationsID = GL20.glGetUniformLocation(shader, "translateTexture");
            activeProgram = shader;
        }

        modelAngle.z = angle;
        modelPos.x = x;
        modelPos.y = y;
       
        modelScale.x = scalex;
        modelScale.y = scaley;
       
        viewMatrix = new Matrix4f();
        modelMatrix = new Matrix4f();

        Matrix4f.translate(cameraPos, viewMatrix, viewMatrix);
       
        Matrix4f.translate(modelPos, modelMatrix, modelMatrix);
        Matrix4f.rotate(modelAngle.z, new Vector3f(0, 0, 1), modelMatrix, modelMatrix);
        //Matrix4f.rotate(this.degreesToRadians(modelAngle.y), new Vector3f(0, 1, 0), modelMatrix, modelMatrix);
       //Matrix4f.rotate(this.degreesToRadians(modelAngle.x), new Vector3f(1, 0, 0), modelMatrix, modelMatrix);
       Matrix4f.scale(modelScale, modelMatrix, modelMatrix);
       
        projectionMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(projectionMatrixLocation, false, matrix44Buffer);
        viewMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(viewMatrixLocation, false, matrix44Buffer);
        modelMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(modelMatrixLocation, false, matrix44Buffer);
       
        if (in!=null) {
            for (int i=0; i<in.length; i++) {
                switch (in[i].values.length) {
                    case 1:
                        GL20.glUniform1f(in[i].location, in[i].values[0]);
                        break;
                    case 2:
                        GL20.glUniform2f(in[i].location, in[i].values[0], in[i].values[1]);
                        break;
                    case 3:
                        GL20.glUniform3f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2]);
                        break;
                    case 4:
                        GL20.glUniform4f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2], in[i].values[3]);
                        break;
                }
            }
        }
       
        GL20.glUniform2f(textureBeginID, texture.drawBeginX, texture.drawBeginY);
        GL20.glUniform2f(textureTranslationsID, texture.drawSizeX, texture.drawSizeY);
       
        if (texture.ID!=activeTexture) {
            GL13.glActiveTexture(GL13.GL_TEXTURE0);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.ID);
            activeTexture = texture.ID;
        }

        GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
    }
   
    public void renderShift(Tex texture, int shader, float x, float y, float shiftx, float shifty, float scalex, float scaley, ShaderInput...in) {
        renderShift(texture, shader, x, y, shiftx, shifty, scalex, scaley, 0, in);
    }
   
    public void renderShift(Tex texture, int shader, float x, float y, float shiftx, float shifty, float scalex, float scaley, float angle, ShaderInput...in) {
        x = (x*2)-Graphics.WIDTH;
        y = (y*2)-Graphics.HEIGHT;
        scalex*=2;
        scaley*=2;
        if (shader!=activeProgram) {
            GL20.glUseProgram(shader);
            projectionMatrixLocation = GL20.glGetUniformLocation(shader, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(shader, "viewMatrix");
            modelMatrixLocation = GL20.glGetUniformLocation(shader, "modelMatrix");
            if (in!=null) {
                for (int i=0; i<in.length; i++) {
                    in[i].location = GL20.glGetUniformLocation(shader, in[i].name);
                }
            }
            textureBeginID = GL20.glGetUniformLocation(shader, "beginTexture");
            textureTranslationsID = GL20.glGetUniformLocation(shader, "translateTexture");
            activeProgram = shader;
        }

        modelAngle.z = angle;
        modelPos.x = x;
        modelPos.y = y;
       
        modelScale.x = scalex;
        modelScale.y = scaley;
       
        modelShift.x = shiftx;
        modelShift.y = shifty;
       
        viewMatrix = new Matrix4f();
        modelMatrix = new Matrix4f();

        Matrix4f.translate(cameraPos, viewMatrix, viewMatrix);
       
        Matrix4f.translate(modelPos, modelMatrix, modelMatrix);
        Matrix4f.rotate(modelAngle.z, new Vector3f(0, 0, 1), modelMatrix, modelMatrix);
        Matrix4f.translate(modelShift, modelMatrix, modelMatrix);
        //Matrix4f.rotate(this.degreesToRadians(modelAngle.y), new Vector3f(0, 1, 0), modelMatrix, modelMatrix);
       //Matrix4f.rotate(this.degreesToRadians(modelAngle.x), new Vector3f(1, 0, 0), modelMatrix, modelMatrix);
       Matrix4f.scale(modelScale, modelMatrix, modelMatrix);
       
        projectionMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(projectionMatrixLocation, false, matrix44Buffer);
        viewMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(viewMatrixLocation, false, matrix44Buffer);
        modelMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(modelMatrixLocation, false, matrix44Buffer);
       
        if (in!=null) {
            for (int i=0; i<in.length; i++) {
                switch (in[i].values.length) {
                    case 1:
                        GL20.glUniform1f(in[i].location, in[i].values[0]);
                        break;
                    case 2:
                        GL20.glUniform2f(in[i].location, in[i].values[0], in[i].values[1]);
                        break;
                    case 3:
                        GL20.glUniform3f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2]);
                        break;
                    case 4:
                        GL20.glUniform4f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2], in[i].values[3]); //<-this line
                       break;
                }
            }
        }
       
        GL20.glUniform2f(textureBeginID, texture.drawBeginX, texture.drawBeginY);
        GL20.glUniform2f(textureTranslationsID, texture.drawSizeX, texture.drawSizeY);
       
        if (texture.ID!=activeTexture) {
            GL13.glActiveTexture(GL13.GL_TEXTURE0);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.ID);
            activeTexture = texture.ID;
        }

        GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
    }
   
    public void setCamera(float x, float y) {
        cameraPos.x = x;
        cameraPos.y = y;
    }
   
    public void endRendering() {
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
        GL20.glDisableVertexAttribArray(0);
        GL20.glDisableVertexAttribArray(1);
        GL20.glDisableVertexAttribArray(2);
        GL30.glBindVertexArray(0);

        GL20.glUseProgram(0);
    }
   
    private void setupMatrices(int width, int height) {
        projectionMatrix = GCore.matrix.orthoMatrix(width, height, -0.1f, 1.1f);
       
        viewMatrix = new Matrix4f();

        modelMatrix = new Matrix4f();

        matrix44Buffer = BufferUtils.createFloatBuffer(16);
    }
   
    private void setupQuad() {
        Vertex v0 = new Vertex();
        v0.setXYZ(-0.5f, 0.5f, 0); v0.setRGB(1, 1, 1); v0.setST(0, 0);
        Vertex v1 = new Vertex();
        v1.setXYZ(-0.5f, -0.5f, 0); v1.setRGB(1, 1, 1); v1.setST(0, 1);
        Vertex v2 = new Vertex();
        v2.setXYZ(0.5f, -0.5f, 0); v2.setRGB(1, 1, 1); v2.setST(1, 1);
        Vertex v3 = new Vertex();
        v3.setXYZ(0.5f, 0.5f, 0); v3.setRGB(1, 1, 1); v3.setST(1, 0);

        vertices = new Vertex[] {v0, v1, v2, v3};
       
        verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * Vertex.stride);            
        FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer();
        for (int i = 0; i < vertices.length; i++) {
                verticesFloatBuffer.put(vertices[i].getElements());
        }
        verticesFloatBuffer.flip();

        byte[] indices = {
                        0, 1, 2,
                        2, 3, 0
        };
        indicesCount = indices.length;
        ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
        indicesBuffer.put(indices);
        indicesBuffer.flip();

        vaoId = GL30.glGenVertexArrays();
        GL30.glBindVertexArray(vaoId);

        vboId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STATIC_DRAW);

        GL20.glVertexAttribPointer(0, Vertex.positionElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.positionByteOffset);
        GL20.glVertexAttribPointer(1, Vertex.colorElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.colorByteOffset);
        GL20.glVertexAttribPointer(2, Vertex.textureElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.textureByteOffset);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        GL30.glBindVertexArray(0);

        vboiId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        modelPos = new Vector3f(0, 0, 0);
        modelShift = new Vector3f(0, 0, 0);
        modelAngle = new Vector3f(0, 0, 0);
        modelScale = new Vector3f(1, 1, 1);
        cameraPos = new Vector3f(0, 0, 0);
    }
   
}


Edit: Shader creation 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  
public class ShaderLoader {
   
    public int loadProgram(String vertexShader, String fragmentShader) {      
        int vsId = loadShader(vertexShader, GL20.GL_VERTEX_SHADER);
        int fsId = loadShader(fragmentShader, GL20.GL_FRAGMENT_SHADER);

        int pId = GL20.glCreateProgram();
        GL20.glAttachShader(pId, vsId);
        GL20.glAttachShader(pId, fsId);
        GL20.glLinkProgram(pId);

        GL20.glBindAttribLocation(pId, 0, "in_Position");
        GL20.glBindAttribLocation(pId, 1, "in_Color");
        GL20.glBindAttribLocation(pId, 2, "in_TextureCoord");

        GL20.glValidateProgram(pId);
       
        return pId;
    }
   
    private int loadShader(String filename, int type) {
        int shaderID = 0;
        String shaderSource="";
        try {
                InputStream in = this.getClass().getResourceAsStream(filename);
                while (in.available()>0) {
                    shaderSource = shaderSource.concat(String.valueOf((char)in.read()));
                }
        } catch (IOException e) {
                System.err.println("Cannot read shader: "+filename);
                e.printStackTrace();
                System.exit(-1);
        }

        shaderID = GL20.glCreateShader(type);
        GL20.glShaderSource(shaderID, shaderSource);
        GL20.glCompileShader(shaderID);

        return shaderID;
    }
   
}


1  
2  
3  
        SL.defaultShader = GCore.shaderLoader.loadProgram("/Core/Graphics/Shaders/defaultShader.vert", "/Core/Graphics/Shaders/defaultShader.frag");
        SL.coloredShader = GCore.shaderLoader.loadProgram("/Core/Graphics/Shaders/defaultShader.vert", "/Core/Graphics/Shaders/coloredShader.frag");
        SL.postProcess = GCore.shaderLoader.loadProgram("/Core/Graphics/Shaders/postProcess.vert", "/Core/Graphics/Shaders/postProcess.frag");
22  Java Game APIs & Engines / OpenGL Development / [SOLVED] Strange error - LWJGL game working on one computer but not on another on: 2013-03-02 22:13:20
Like in topic. I am developing game in team of two people - I am programming on Windows, official JDK while second programmer is working on Linux, OpenJDK. We are using the same LWJGL version. Code is working for me, but my teammate sees this message:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
Exception in thread "main" org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
at org.lwjgl.opengl.Util.checkGLError(Util.java:59)
at org.lwjgl.opengl.GL20.glUniform4f(GL20.java:365)
at Lib.Graphics.RenderEngine.renderShift(RenderEngine.java:210)
at Objects.Ships.PlayerShip.draw(PlayerShip.java:51)
at Core.Graphics.Graphics.update(Graphics.java:48)
at Core.Core.<init>(Core.java:44)
at Core.Core.main(Core.java:20)
Java Result: 1
BUILD SUCCESSFUL (total time: 13 seconds)


What can cause this problem? I am sure that everything is set right on both computers, game was running without problems until the engine upgrade.

Here is the RenderEngine class (most important fragments):

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  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
package Lib.Graphics;

import Core.Graphics.Graphics;
import Lib.Graphics.Shaders.ShaderInput;
import Lib.Graphics.Textures.Tex;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;

public class RenderEngine {
   
    private int activeProgram = 0;
    private int activeTexture = 0;
   
    private int vaoId = 0;
    private int vboId = 0;
    private int vboiId = 0;
    private int indicesCount = 0;
    private Vertex[] vertices = null;
    private ByteBuffer verticesByteBuffer = null;
   
    private int textureBeginID = 0;
    private int textureTranslationsID = 0;
    private int projectionMatrixLocation = 0;
    private int viewMatrixLocation = 0;
    private int modelMatrixLocation = 0;
    private Matrix4f projectionMatrix = null;
    private Matrix4f viewMatrix = null;
    private Matrix4f modelMatrix = null;
    private Vector3f modelPos = null;
    private Vector3f modelShift = null;
    private Vector3f modelAngle = null;
    private Vector3f modelScale = null;
    private Vector3f cameraPos = null;
    private FloatBuffer matrix44Buffer = null;
   
    public RenderEngine() {}
   
    public void initialize(int width, int height) {
        setupMatrices(width, height);
        setupQuad();
    }
   
    public void startDrawing() {
        GL20.glUseProgram(activeProgram);
       
        GL30.glBindVertexArray(vaoId);
        GL20.glEnableVertexAttribArray(0);
        GL20.glEnableVertexAttribArray(1);
        GL20.glEnableVertexAttribArray(2);

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
       
        setCamera(0, 0);
    }
   
    public void render(Tex texture, int shader, float x, float y, float scalex, float scaley, float angle, ShaderInput...in) {
        x = (x*2)-Graphics.WIDTH;
        y = (y*2)-Graphics.HEIGHT;
        scalex*=2;
        scaley*=2;
        if (shader!=activeProgram) {
            GL20.glUseProgram(shader);
            projectionMatrixLocation = GL20.glGetUniformLocation(shader, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(shader, "viewMatrix");
            modelMatrixLocation = GL20.glGetUniformLocation(shader, "modelMatrix");
            if (in!=null) {
                for (int i=0; i<in.length; i++) {
                    in[i].location = GL20.glGetUniformLocation(shader, in[i].name);
                }
            }
            textureBeginID = GL20.glGetUniformLocation(shader, "beginTexture");
            textureTranslationsID = GL20.glGetUniformLocation(shader, "translateTexture");
            activeProgram = shader;
        }

        modelAngle.z = angle;
        modelPos.x = x;
        modelPos.y = y;
       
        modelScale.x = scalex;
        modelScale.y = scaley;
       
        viewMatrix = new Matrix4f();
        modelMatrix = new Matrix4f();

        Matrix4f.translate(cameraPos, viewMatrix, viewMatrix);
       
        Matrix4f.translate(modelPos, modelMatrix, modelMatrix);
        Matrix4f.rotate(modelAngle.z, new Vector3f(0, 0, 1), modelMatrix, modelMatrix);
        Matrix4f.scale(modelScale, modelMatrix, modelMatrix);
       
        projectionMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(projectionMatrixLocation, false, matrix44Buffer);
        viewMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(viewMatrixLocation, false, matrix44Buffer);
        modelMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(modelMatrixLocation, false, matrix44Buffer);
       
        if (in!=null) {
            for (int i=0; i<in.length; i++) {
                switch (in[i].values.length) {
                    case 1:
                        GL20.glUniform1f(in[i].location, in[i].values[0]);
                        break;
                    case 2:
                        GL20.glUniform2f(in[i].location, in[i].values[0], in[i].values[1]);
                        break;
                    case 3:
                        GL20.glUniform3f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2]);
                        break;
                    case 4:
                        GL20.glUniform4f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2], in[i].values[3]);
                        break;
                }
            }
        }
       
        GL20.glUniform2f(textureBeginID, texture.drawBeginX, texture.drawBeginY);
        GL20.glUniform2f(textureTranslationsID, texture.drawSizeX, texture.drawSizeY);
       
        if (texture.ID!=activeTexture) {
            GL13.glActiveTexture(GL13.GL_TEXTURE0);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.ID);
            activeTexture = texture.ID;
        }

        GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
    }
   
    public void endRendering() {
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
        GL20.glDisableVertexAttribArray(0);
        GL20.glDisableVertexAttribArray(1);
        GL20.glDisableVertexAttribArray(2);
        GL30.glBindVertexArray(0);

        GL20.glUseProgram(0);
    }
   
    private void setupMatrices(int width, int height) {
        projectionMatrix = GCore.matrix.orthoMatrix(width, height, -0.1f, 1.1f);
       
        viewMatrix = new Matrix4f();

        modelMatrix = new Matrix4f();

        matrix44Buffer = BufferUtils.createFloatBuffer(16);
    }
   
    private void setupQuad() {
        Vertex v0 = new Vertex();
        v0.setXYZ(-0.5f, 0.5f, 0); v0.setRGB(1, 1, 1); v0.setST(0, 0);
        Vertex v1 = new Vertex();
        v1.setXYZ(-0.5f, -0.5f, 0); v1.setRGB(1, 1, 1); v1.setST(0, 1);
        Vertex v2 = new Vertex();
        v2.setXYZ(0.5f, -0.5f, 0); v2.setRGB(1, 1, 1); v2.setST(1, 1);
        Vertex v3 = new Vertex();
        v3.setXYZ(0.5f, 0.5f, 0); v3.setRGB(1, 1, 1); v3.setST(1, 0);

        vertices = new Vertex[] {v0, v1, v2, v3};
       
        verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * Vertex.stride);            
        FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer();
        for (int i = 0; i < vertices.length; i++) {
                verticesFloatBuffer.put(vertices[i].getElements());
        }
        verticesFloatBuffer.flip();

        byte[] indices = {
                        0, 1, 2,
                        2, 3, 0
        };
        indicesCount = indices.length;
        ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
        indicesBuffer.put(indices);
        indicesBuffer.flip();

        vaoId = GL30.glGenVertexArrays();
        GL30.glBindVertexArray(vaoId);

        vboId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STATIC_DRAW);

        GL20.glVertexAttribPointer(0, Vertex.positionElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.positionByteOffset);
        GL20.glVertexAttribPointer(1, Vertex.colorElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.colorByteOffset);
        GL20.glVertexAttribPointer(2, Vertex.textureElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.textureByteOffset);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        GL30.glBindVertexArray(0);

        vboiId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        modelPos = new Vector3f(0, 0, 0);
        modelShift = new Vector3f(0, 0, 0);
        modelAngle = new Vector3f(0, 0, 0);
        modelScale = new Vector3f(1, 1, 1);
        cameraPos = new Vector3f(0, 0, 0);
    }
   
}


I am using this code like this:
1  
GCore.renderer.render(TL.blankHex, SL.coloredShader, x, y, scaleX, scaleY, rotate, new ShaderInput("color", 0, 1, 1, 1));


ShaderInput class:

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  
package Lib.Graphics.Shaders;

public class ShaderInput {
    public int location;
   
    public float[] values;
    public String name;
   
    public ShaderInput(String name, float value1, float value2, float value3, float value4) {
        this.name = name;
        this.values = new float[4];
        this.values[0] = value1;
        this.values[1] = value2;
        this.values[2] = value3;
        this.values[3] = value3;
    }
   
    public ShaderInput(String name, float value1, float value2, float value3) {
        this.name = name;
        this.values = new float[3];
        this.values[0] = value1;
        this.values[1] = value2;
        this.values[2] = value3;
    }
   
    public ShaderInput(String name, float value1, float value2) {
        this.name = name;
        this.values = new float[2];
        this.values[0] = value1;
        this.values[1] = value2;
    }
   
    public ShaderInput(String name, float value1) {
        this.name = name;
        this.values = new float[1];
        this.values[0] = value1;
    }
}


This is SL.coloredShader fragment shader (I am sure that vector shader don't contain any errors):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
#version 150 core

uniform sampler2D texture_diffuse;
uniform vec2 beginTexture;
uniform vec2 translateTexture;
uniform vec4 color;

in vec4 pass_Color;
in vec2 pass_TextureCoord;

out vec4 out_Color;

void main(void) {
    out_Color = texture2D(texture_diffuse, pass_TextureCoord*translateTexture+beginTexture)*(pass_Color*color);
}


We have tried many changes in code, but still can't find out why code is not working. I apologize for the amount of code in this thread, but we can't figure out where is the cause of the problem.
23  Java Game APIs & Engines / OpenGL Development / Re: LWJGL using modern OpenGL examples or Open Source on: 2013-03-01 19:55:06
I am usign matrices even though I am making 2D game - this has lots of benefits: the game look the same on every computer, everything is displayed correctly, you an easily manipulate everything.
24  Java Game APIs & Engines / OpenGL Development / Re: LWJGL using modern OpenGL examples or Open Source on: 2013-03-01 14:57:52
I see that you don't have any matrixes - movement in modern OpenGL is all about shaders and matrixes, so you should add them.
25  Java Game APIs & Engines / OpenGL Development / Re: LWJGL using modern OpenGL examples or Open Source on: 2013-03-01 12:26:11
Do you clear screen buffers each frame using glClear?
26  Game Development / Newbie & Debugging Questions / Re: [Question] Organizing Code on: 2013-02-26 20:48:17
My code organization currently looks like this:

  • Core
    • Textures list (class full of public static Tex (class which store informations about textures) which can be used in rendering)
    • Shaders list (class full of shaders ID's)
    • Preloader (loads all texture and shaders data into Textures list and Shaders list)
    • Loop
    • Input
    • Logic (can read data only from input, almost every object and interface element is created there)
    • Collisions (if needed for the game, can read and save data in logic)
    • Graphics (can read data only from logic)
    • Audio (can read data only from logic)
  • Objects
    Everything what is displayed in your game (except interface) - background entities, player, enemies, bullets etc.
  • Interface
    Name speaks all. I am using interface classes for everything related to interface, with exception of mouse cursor (controlled directly by core).
  • Libraries
    Storage of all "high-level" functions which allows me to do things like rendering, loading assets etc. using only one function.

This system works well - I'm not very experienced, but at the moment I have about 100 classes in my project and everything is still prefectly clear.

I hope this helps. Wink
27  Java Game APIs & Engines / OpenGL Development / Re: What version of OpenGL to use? on: 2013-02-22 15:56:34
If you want to use shaders, OpenGL 3.2 is much better choice than fixed pipeline, old OpenGL. It is much, much harder, but much better performance is worth it.
28  Game Development / Newbie & Debugging Questions / Re: Vector2D class. float or double? [noob-alert] on: 2013-02-22 12:32:55
You can make your own float Math class. I suggest you using mostly floats, use doubles only when you need bigger precision.
29  Java Game APIs & Engines / OpenGL Development / Re: Fast and easy projection matrix for 2d only rendering? on: 2013-02-22 09:18:22
This is 'old' OpenGL way.

Is there any sense to add projection matrix if setting viewpoint to (height, height) and calculating aspect ratio (for things like interface rendering which must be always displayed in the fixed place on screen) works well?
30  Java Game APIs & Engines / OpenGL Development / Re: Fast and easy projection matrix for 2d only rendering? on: 2013-02-21 22:33:03
It seems that the best solution is... Removing the whole projection matrix and leave only view and model matrixes, then scalling x in this way: wanted_scale/(game_width/game_height). Can I do the same using projection matrix?
Pages: [1] 2 3 ... 6
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (65 views)
2013-05-17 21:29:12

alaslipknot (74 views)
2013-05-16 21:24:48

gouessej (105 views)
2013-05-16 00:53:38

gouessej (102 views)
2013-05-16 00:17:58

theagentd (111 views)
2013-05-15 15:01:13

theagentd (102 views)
2013-05-15 15:00:54

StreetDoggy (146 views)
2013-05-14 15:56:26

kutucuk (169 views)
2013-05-12 17:10:36

kutucuk (168 views)
2013-05-12 15:36:09

UnluckyDevil (177 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 1.455 seconds with 20 queries.