Hello Guest

glEnableVertexAttribArray black background

  • 8 Replies
  • 1152 Views
*

Offline begin

  • *
  • 12
glEnableVertexAttribArray black background
« on: November 01, 2018, 21:31:55 »
Sorry for my children's questions
There is simply no time for a specific library study.

Okey, I have problem with black ground in my demo game
When I put a different texture for the sky (I make the Skybox) the background is still black
I realized that this is due to this line:

Code: [Select]
normalAttribute = glGetAttribLocationARB(program, "aNormal");
        glEnableVertexAttribArrayARB(normalAttribute);

But I when tried remove her or change on glDisableVertexAttribArrayARB - I get it:



instead of the usual shadow.....

My methods with load program:

Code: [Select]
static int createShader(String resource, int type) throws IOException {
        int shader = glCreateShaderObjectARB(type);
        ByteBuffer source = ioResourceToByteBuffer(resource, 1024);
        PointerBuffer strings = BufferUtils.createPointerBuffer(1);
        IntBuffer lengths = BufferUtils.createIntBuffer(1);
        strings.put(0, source);
        lengths.put(0, source.remaining());
        glShaderSourceARB(shader, strings, lengths);
        glCompileShaderARB(shader);
        int compiled = glGetObjectParameteriARB(shader, GL_OBJECT_COMPILE_STATUS_ARB);
        String shaderLog = glGetInfoLogARB(shader);
        if (shaderLog.trim().length() > 0) {
            System.err.println(shaderLog);
        }
        if (compiled == 0) {
            throw new AssertionError("Could not compile shader");
        }
        return shader;
    }

    void createProgram() throws IOException {

        program = glCreateProgramObjectARB();
        int vertexShader = createShader("org/lwjgl/demo/opengl/assimp/magnet.vs",
                GL_VERTEX_SHADER_ARB);
        int fragmentShader = createShader("org/lwjgl/demo/opengl/assimp/magnet.fs",
                GL_FRAGMENT_SHADER_ARB);
        glAttachObjectARB(program, vertexShader);
        glAttachObjectARB(program, fragmentShader);
        glLinkProgramARB(program);
        int linkStatus = glGetObjectParameteriARB(program, GL_OBJECT_LINK_STATUS_ARB);
        String programLog = glGetInfoLogARB(program);
        if (programLog.trim().length() > 0) {
            System.err.println(programLog);
        }
        if (linkStatus == 0) {
            throw new AssertionError("Could not link program");
        }

        glUseProgramObjectARB(program);
        vertexAttribute = glGetAttribLocationARB(program, "aVertex");
        glEnableVertexAttribArrayARB(vertexAttribute);
        normalAttribute = glGetAttribLocationARB(program, "aNormal");
        glEnableVertexAttribArrayARB(normalAttribute);
        modelMatrixUniform = glGetUniformLocationARB(program, "uModelMatrix");
        viewProjectionMatrixUniform = glGetUniformLocationARB(program, "uViewProjectionMatrix");
        normalMatrixUniform = glGetUniformLocationARB(program, "uNormalMatrix");
        lightPositionUniform = glGetUniformLocationARB(program, "uLightPosition");
        viewPositionUniform = glGetUniformLocationARB(program, "uViewPosition");
        ambientColorUniform = glGetUniformLocationARB(program, "uAmbientColor");
        diffuseColorUniform = glGetUniformLocationARB(program, "uDiffuseColor");
        specularColorUniform = glGetUniformLocationARB(program, "uSpecularColor");
    }

Accordingly, when I add a new program (in this case, the skybox), nothing changes, and the background continues to be black.
I repeat. If I delete this line, the sky will appear, but the shadow of the model will disappear.





*

Offline begin

  • *
  • 12
Re: glEnableVertexAttribArray black background
« Reply #1 on: November 01, 2018, 21:33:11 »
And file magnet.vs

Code: [Select]
#version 110

attribute vec4 aVertex;
attribute vec3 aNormal;
uniform mat4 uModelMatrix;
uniform mat4 uViewProjectionMatrix;
uniform mat3 uNormalMatrix;
varying vec3 vPosition;
varying vec3 vNormal;

void main() {
    vec4 modelPosition = uModelMatrix * aVertex * vec4(0.1, 0.1, 0.1, 1.0);
    gl_Position = uViewProjectionMatrix * modelPosition;
    vPosition = modelPosition.xyz;
    vNormal = uNormalMatrix * aNormal;
}

Re: glEnableVertexAttribArray black background
« Reply #2 on: November 02, 2018, 06:08:13 »
Just a humble, off-topic question. When you're writing "There is simply no time for a specific library study.", what do you mean? Do you have a deadline or whatever? I studied 2 years OpenGL and now I feel comfortable myself.

Getting into OpenGL quickly and expecting result that you really understand is tough. Also, you don't have to study LWJGL as it's a wrapper only, you have to study OpenGL itself.

*

Offline begin

  • *
  • 12
Re: glEnableVertexAttribArray black background
« Reply #3 on: November 02, 2018, 10:44:53 »
The term is. Less than 6 months. I do not think that I will learn at least half of the library in such a period of time, I just have a task in hand, which I need create.
Do not think that as soon as I haved a problem, I immediately go here. In fact, I can spend all my free time on this, but without finding a solution. But it is temporary, at the beginning of the study is always difficult.

So what about my mistake in this thread, can you help me? (Sorry for my bad language)

Re: glEnableVertexAttribArray black background
« Reply #4 on: November 02, 2018, 18:54:50 »
Can you share your full code somewhere? I see minor stuff in the attached code snippets, but to be exact I need to see the whole stuff.

*

Offline begin

  • *
  • 12
Re: glEnableVertexAttribArray black background
« Reply #5 on: November 02, 2018, 20:40:25 »

Re: glEnableVertexAttribArray black background
« Reply #6 on: November 03, 2018, 07:49:25 »
I pass this to someone, who has more than half an hour to investigate this. You wrote you have 6 month, I would spend the first month at least to go through on this tutorial: https://ahbejarano.gitbook.io/lwjglgamedev/

If you don't do this, you will hit walls every day.

*

Offline KaiHH

  • ***
  • 149
Re: glEnableVertexAttribArray black background
« Reply #7 on: November 03, 2018, 13:30:38 »
In order for your code to work, you would need to make the following changes (unified diff format):
Code: [Select]
@@ -30,6 +30,7 @@ import static org.lwjgl.opengl.ARBShaderObjects.*;
 import static org.lwjgl.opengl.ARBVertexBufferObject.*;
 import static org.lwjgl.opengl.ARBVertexShader.GL_VERTEX_SHADER_ARB;
 import static org.lwjgl.opengl.ARBVertexShader.glEnableVertexAttribArrayARB;
+import static org.lwjgl.opengl.ARBVertexShader.glDisableVertexAttribArrayARB;
 import static org.lwjgl.opengl.ARBVertexShader.glGetAttribLocationARB;
 import static org.lwjgl.opengl.GL11.GL_LINEAR;
 import static org.lwjgl.opengl.GL11.GL_LINEAR_MIPMAP_LINEAR;
@@ -298,9 +299,7 @@ public class WavefrontObjDemo {
         glUseProgramObjectARB(cubemapProgram);
 
         vertexAttribute = glGetAttribLocationARB(program, "aVertex");
-        glEnableVertexAttribArrayARB(vertexAttribute);
         normalAttribute = glGetAttribLocationARB(program, "aNormal");
-        glEnableVertexAttribArrayARB(normalAttribute);
 
         modelMatrixUniform = glGetUniformLocationARB(program, "uModelMatrix");
         viewProjectionMatrixUniform = glGetUniformLocationARB(program, "uViewProjectionMatrix");
@@ -337,6 +336,7 @@ public class WavefrontObjDemo {
         viewMatrix.setLookAt(viewPosition.x, viewPosition.y, viewPosition.z, 0f, 0f, 0f, 0f, 1f,
                 0f);
         projectionMatrix.mul(viewMatrix, viewProjectionMatrix);
+        invViewProjMatrix.set(viewMatrix).setTranslation(0, 0, 0).mulLocal(projectionMatrix).invert(invViewProjMatrix);
 
         glUseProgramObjectARB(cubemapProgram);
         glUniformMatrix4fv(cubemap_invViewProjUniform, false, invViewProjMatrix.get(matrixBuffer));
@@ -354,7 +354,8 @@ public class WavefrontObjDemo {
         drawCubemap();
 
         glUseProgram(program);
-
+        glEnableVertexAttribArrayARB(vertexAttribute);
+        glEnableVertexAttribArrayARB(normalAttribute);
         for (Model.Mesh mesh : model.meshes) {
 
             glBindBuffer(GL_ARRAY_BUFFER, mesh.vertexArrayBuffer);
@@ -381,6 +382,8 @@ public class WavefrontObjDemo {
             glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.elementArrayBuffer);
             glDrawElements(GL_TRIANGLES, mesh.elementCount, GL_UNSIGNED_INT, 0);
         }
+        glDisableVertexAttribArrayARB(vertexAttribute);
+        glDisableVertexAttribArrayARB(normalAttribute);
     }

But I also share the point of mudlee. You seem to be taking on a task which is way over your head and you must spend some more time learning OpenGL.
What you are currently doing is just stitching some snippets from lwjgl3-demos programs together and expecting that to work.

*

Offline begin

  • *
  • 12
Re: glEnableVertexAttribArray black background
« Reply #8 on: November 06, 2018, 16:54:08 »
Thanks, it helped me.
Sorry for the big wait.
I followed your advice and am already studying the library at the root.