Skip to content

Commit

Permalink
Fixed rendering bug!
Browse files Browse the repository at this point in the history
  • Loading branch information
CreedVI committed Dec 26, 2021
1 parent a23b40a commit acf6770
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/com/raylib/java/JarMainForTesting.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

public class JarMainForTesting{

static Raylib rlj = new Raylib();
static Raylib rlj;

public static void main(String[] args){
rlj.core.InitWindow(800, 600, null);
rlj = new Raylib(800, 600, null);
rlj.core.SetTargetFPS(60);

while(!rlj.core.WindowShouldClose()){
Expand Down
34 changes: 17 additions & 17 deletions src/com/raylib/java/rlgl/RLGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,17 @@ public static class rlShaderLocationIndex{
RL_SHADER_LOC_COLOR_DIFFUSE = 12, // Shader location: vector uniform: diffuse color
RL_SHADER_LOC_COLOR_SPECULAR = 13, // Shader location: vector uniform: specular color
RL_SHADER_LOC_COLOR_AMBIENT = 14, // Shader location: vector uniform: ambient color
RL_SHADER_LOC_MAP_ALBEDO = 12, // Shader location: sampler2d texture: albedo (same as: SHADER_LOC_MAP_DIFFUSE)
RL_SHADER_LOC_MAP_METALNESS = 13, // Shader location: sampler2d texture: metalness (same as: SHADER_LOC_MAP_SPECULAR)
RL_SHADER_LOC_MAP_NORMAL = 15, // Shader location: sampler2d texture: normal
RL_SHADER_LOC_MAP_ROUGHNESS = 16, // Shader location: sampler2d texture: roughness
RL_SHADER_LOC_MAP_OCCLUSION = 17, // Shader location: sampler2d texture: occlusion
RL_SHADER_LOC_MAP_EMISSION = 18, // Shader location: sampler2d texture: emission
RL_SHADER_LOC_MAP_HEIGHT = 19, // Shader location: sampler2d texture: height
RL_SHADER_LOC_MAP_CUBEMAP = 20, // Shader location: samplerCube texture: cubemap
RL_SHADER_LOC_MAP_IRRADIANCE = 21, // Shader location: samplerCube texture: irradiance
RL_SHADER_LOC_MAP_PREFILTER = 22, // Shader location: samplerCube texture: prefilter
RL_SHADER_LOC_MAP_BRDF = 23; // Shader location: sampler2d texture: brdf
RL_SHADER_LOC_MAP_ALBEDO = 15, // Shader location: sampler2d texture: albedo (same as: SHADER_LOC_MAP_DIFFUSE)
RL_SHADER_LOC_MAP_METALNESS = 16, // Shader location: sampler2d texture: metalness (same as: SHADER_LOC_MAP_SPECULAR)
RL_SHADER_LOC_MAP_NORMAL = 17, // Shader location: sampler2d texture: normal
RL_SHADER_LOC_MAP_ROUGHNESS = 18, // Shader location: sampler2d texture: roughness
RL_SHADER_LOC_MAP_OCCLUSION = 19, // Shader location: sampler2d texture: occlusion
RL_SHADER_LOC_MAP_EMISSION = 20, // Shader location: sampler2d texture: emission
RL_SHADER_LOC_MAP_HEIGHT = 21, // Shader location: sampler2d texture: height
RL_SHADER_LOC_MAP_CUBEMAP = 22, // Shader location: samplerCube texture: cubemap
RL_SHADER_LOC_MAP_IRRADIANCE = 23, // Shader location: samplerCube texture: irradiance
RL_SHADER_LOC_MAP_PREFILTER = 24, // Shader location: samplerCube texture: prefilter
RL_SHADER_LOC_MAP_BRDF = 25; // Shader location: sampler2d texture: brdf

public final static int
RL_SHADER_LOC_MAP_DIFFUSE = RL_SHADER_LOC_MAP_ALBEDO,
Expand Down Expand Up @@ -1470,7 +1470,6 @@ else if(GRAPHICS_API_OPENGL_ES2){
// Vertex color buffer (shader-location = 3)
ByteBuffer colours = ByteBuffer.allocateDirect(batch.rlVertexBuffer[i].colors.length);
colours.put(batch.rlVertexBuffer[i].colors).flip();

batch.rlVertexBuffer[i].vboId[2] = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, batch.rlVertexBuffer[i].vboId[2]);
glBufferData(GL_ARRAY_BUFFER, colours, GL_DYNAMIC_DRAW);
Expand Down Expand Up @@ -1655,15 +1654,15 @@ static void rlDrawRenderBatch(rlRenderBatch batch){
// Bind vertex attrib: color (shader-location = 3)
glBindBuffer(GL_ARRAY_BUFFER, batch.rlVertexBuffer[batch.currentBuffer].vboId[2]);
glVertexAttribPointer(rlglData.getState().currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR],
4, GL_FLOAT, false, 0, 0);
4, GL_UNSIGNED_BYTE, true, 0, 0);
glEnableVertexAttribArray(rlglData.getState().currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR]);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.rlVertexBuffer[batch.currentBuffer].vboId[3]);
}

// Setup some default shader values
glUniform4f(rlglData.getState().currentShaderLocs[RL_SHADER_LOC_COLOR_DIFFUSE], 1.0f, 1.0f, 1.0f, 1.0f);
glUniform1i(rlglData.getState().currentShaderLocs[RL_SHADER_LOC_MAP_ALBEDO], 0); // Active default sampler2D: texture0
glUniform1i(rlglData.getState().currentShaderLocs[RL_SHADER_LOC_MAP_DIFFUSE], 0); // Active default sampler2D: texture0

// Activate additional sampler textures
// Those additional textures will be common for all draw calls of the batch
Expand All @@ -1678,7 +1677,6 @@ static void rlDrawRenderBatch(rlRenderBatch batch){
// NOTE: Batch system accumulates calls by texture0 changes, additional textures are enabled for all the draw calls
glActiveTexture(GL_TEXTURE0);


for (int i = 0, vertexOffset = 0; i < batch.drawCounter; i++){
// Bind current draw call texture, activated as GL_TEXTURE0 and binded to sampler2D texture0 by default
glBindTexture(GL_TEXTURE_2D, batch.draws[i].textureId);
Expand Down Expand Up @@ -2971,8 +2969,9 @@ public int rlLoadShaderCode(String vsCode, String fsCode){
}
}

// Get available shader uniforms
/* Get available shader uniforms
// NOTE: This information is useful for debug...
// NOTE: glGetProgramiv() causes the JRE to crash...
IntBuffer uniformCount = IntBuffer.allocate(64);
glGetProgramiv(id, GL_ACTIVE_UNIFORMS, uniformCount);
Expand All @@ -2987,6 +2986,7 @@ public int rlLoadShaderCode(String vsCode, String fsCode){
Tracelog(LOG_DEBUG, "SHADER: [ID " + id + "] Active uniform (" + name + ") set at location: " + glGetUniformLocation(id, name));
}
*/
}

return id;
Expand Down Expand Up @@ -3751,7 +3751,7 @@ else if (GRAPHICS_API_OPENGL_33){
// Set default shader locations: uniform locations
rlglData.getState().defaultShaderLocs[RL_SHADER_LOC_MATRIX_MVP] = glGetUniformLocation(rlglData.getState().defaultShaderId, "mvp");
rlglData.getState().defaultShaderLocs[RL_SHADER_LOC_COLOR_DIFFUSE] = glGetUniformLocation(rlglData.getState().defaultShaderId, "colDiffuse");
rlglData.getState().defaultShaderLocs[RL_SHADER_LOC_MAP_ALBEDO] = glGetUniformLocation(rlglData.getState().defaultShaderId, "texture0");
rlglData.getState().defaultShaderLocs[RL_SHADER_LOC_MAP_DIFFUSE] = glGetUniformLocation(rlglData.getState().defaultShaderId, "texture0");
}
else{
Tracelog(LOG_WARNING, "SHADER: [ID " + rlglData.getState().getDefaultShaderId() + "] Failed to load default shader");
Expand Down

0 comments on commit acf6770

Please sign in to comment.