Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
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   
Pages: [1]
  ignore  |  Print  
  [SOLVED] Strange error - LWJGL game working on one computer but not on another  (Read 1488 times)
0 Members and 1 Guest are viewing this topic.
Offline Mac70
« Posted 2013-03-02 21: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.

Check out my Devblog! Smiley
Offline HeroesGraveDev

JGO Kernel


Medals: 254
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-03-02 21:19:51 »

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)


See this?

NONE of the methods in this stack trace are available to us. The error is caused by this chain of methods, but you haven't shown any of them. Please show all the appropriate methods. Smiley

Offline HeroesGraveDev

JGO Kernel


Medals: 254
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #2 - Posted 2013-03-02 21:28:14 »

Can we also see your shader creation code.

The problem is caused by glUniform4f()

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
 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;
                }
            }
        }

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mac70
« Reply #3 - Posted 2013-03-02 21: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");

Check out my Devblog! Smiley
Offline ra4king

JGO Kernel


Medals: 346
Projects: 3
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2013-03-02 22:13:53 »

From the GL spec, the only reasons related to this could be:
Quote
GL_INVALID_OPERATION is generated if there is no current program object.
GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the glUniform command.
GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current program object and location is not equal to -1.

The one most likely is that "location" is invalid. After line 160 of RenderEngine, make sure in[i].location is a valid value (not -1).

Offline HeroesGraveDev

JGO Kernel


Medals: 254
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #5 - Posted 2013-03-02 22:16:06 »

The one most likely is that "location" is invalid. After line 160 of RenderEngine, make sure in.location is a valid value (not -1).

I was just about to ask where the location variable is set.

@OP: ^^ Where is it set?

Offline ra4king

JGO Kernel


Medals: 346
Projects: 3
Exp: 5 years


I'm the King!


« Reply #6 - Posted 2013-03-02 22:20:53 »

The one most likely is that "location" is invalid. After line 160 of RenderEngine, make sure in.location is a valid value (not -1).

I was just about to ask where the location variable is set.

@OP: ^^ Where is it set?
Have you followed the line number I mentioned? Roll Eyes

Offline HeroesGraveDev

JGO Kernel


Medals: 254
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #7 - Posted 2013-03-02 22:24:45 »


Have you followed the line number I mentioned? Roll Eyes

Nope. Didn't see that.

Maybe shader == activeProgram?

Offline Mac70
« Reply #8 - Posted 2013-03-02 22: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);
            }
        }

Check out my Devblog! Smiley
Offline ra4king

JGO Kernel


Medals: 346
Projects: 3
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2013-03-02 22:47:52 »

Ah yup, seems like you're supplying new objects of ShaderInputs ever time. If the shader is constantly active, you are not getting their locations every time.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline deepthought
« Reply #10 - Posted 2013-03-03 03:53:48 »

Don't uniforms and attributes stay in the same location unless the shader is reloaded?
You only need to get locations once when you create the shader, then store them.

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (19 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (31 views)
2014-09-19 03:14:18

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

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

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

Tekkerue (50 views)
2014-09-09 02:24:56
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!