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:
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):
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:
GCore.renderer.render(TL.blankHex, SL.coloredShader, x, y, scaleX, scaleY, rotate, new ShaderInput("color", 0, 1, 1, 1));
ShaderInput class:
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):
#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.