Java 顶点着色器没有绘制任何内容

Java 顶点着色器没有绘制任何内容,java,opengl,jogl,particles,Java,Opengl,Jogl,Particles,我正在尝试使用JOGL在opengl中实现粒子引擎。 我最近将代码更改为使用着色器,以前我只使用数组缓冲区,但效率不够 我没有收到任何链接或编译错误,但根本没有绘制粒子。你们能帮帮我吗 所有glGetUniformLocation返回正值。 gl.glGetStringGL_SHADING_LANGUAGE_版本通过Cg编译器返回4.40 NVIDIA //Rendering particles here private void render_particles(Camera cam)

我正在尝试使用JOGL在opengl中实现粒子引擎。 我最近将代码更改为使用着色器,以前我只使用数组缓冲区,但效率不够

我没有收到任何链接或编译错误,但根本没有绘制粒子。你们能帮帮我吗

所有glGetUniformLocation返回正值。 gl.glGetStringGL_SHADING_LANGUAGE_版本通过Cg编译器返回4.40 NVIDIA

//Rendering particles here
   private void render_particles(Camera cam) {
    GL4 gl = GLContext.getCurrentGL().getGL4();

    gl.glBindBuffer(GL_ARRAY_BUFFER, VB_P_Position);
    gl.glBufferData(GL_ARRAY_BUFFER, particle_position_buffer.capacity() * Float.BYTES, null, GL2ES2.GL_STREAM_DRAW);
    gl.glBufferSubData(GL_ARRAY_BUFFER, 0, particle_position_buffer.capacity() * Float.BYTES, particle_position_buffer);

    gl.glBindBuffer(GL_ARRAY_BUFFER, VB_P_Color);
    gl.glBufferData(GL_ARRAY_BUFFER, particle_color_buffer.capacity() * Float.BYTES, null, GL2ES2.GL_STREAM_DRAW);
    gl.glBufferSubData(GL_ARRAY_BUFFER, 0, particle_color_buffer.capacity() * Float.BYTES, particle_color_buffer);

    gl.glDepthMask(false);
    gl.glEnable(GL_BLEND);
    gl.glBlendFunc(GL_SRC_ALPHA, blendmode);
    gl.glDisable(GLLightingFunc.GL_LIGHTING);

    shader.useShader(gl);
    particleTexture.enable(gl);
    gl.glActiveTexture(GL_TEXTURE0);
    particleTexture.bind(gl);

    gl.glUniform1i(TextureID, texture.getTarget());
    gl.glUniform3f(CameraRight_worldspace_ID, cam.right.x, cam.right.y, cam.right.z);
    gl.glUniform3f(CameraUp_worldspace_ID, cam.up.x, cam.up.y, cam.up.z);

    gl.glUniformMatrix4fv(ViewProjMatrixID, 1, false, cam.MVMatrix);

    gl.glEnableVertexAttribArray(0);
    gl.glBindBuffer(GL_ARRAY_BUFFER, VB_P_Vertex);
    gl.glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

    gl.glEnableVertexAttribArray(1);
    gl.glBindBuffer(GL_ARRAY_BUFFER, VB_P_Position);
    gl.glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, 0);

    gl.glEnableVertexAttribArray(2);
    gl.glBindBuffer(GL_ARRAY_BUFFER, VB_P_Color);
    gl.glVertexAttribPointer(2, 4, GL_FLOAT, false, 0, 0);

    gl.glVertexAttribDivisor(0, 0);
    gl.glVertexAttribDivisor(1, 1);
    gl.glVertexAttribDivisor(2, 1);

    gl.glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, particleProperties.amount);

    shader.dontUseShader(gl);
    gl.glDisableVertexAttribArray(0);
    gl.glDisableVertexAttribArray(1);
    gl.glDisableVertexAttribArray(2);
顶点着色器

#version 330 core

// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 squareVertices;
layout(location = 1) in vec4 xyzs; // Position of the center of the particule and size of the square
layout(location = 2) in vec4 color; // Position of the center of the particule and size of the square

// Output data ; will be interpolated for each fragment.
out vec2 UV;
out vec4 particlecolor;

// Values that stay constant for the whole mesh.
uniform vec3 CameraRight_worldspace;
uniform vec3 CameraUp_worldspace;
uniform mat4 VP; // Model-View-Projection matrix, but without the Model (the position is in BillboardPos; the orientation depends on the camera)

void main()
{
    float particleSize = xyzs.w; // because we encoded it this way.
    vec3 particleCenter_wordspace = xyzs.xyz;

    vec3 vertexPosition_worldspace = 
        particleCenter_wordspace
        + CameraRight_worldspace * squareVertices.x * particleSize
        + CameraUp_worldspace * squareVertices.y * particleSize;

    // Output position of the vertex
    gl_Position = VP * vec4(vertexPosition_worldspace, 1.0f);

    // UV of the vertex. No special space for this one.
    UV = squareVertices.xy + vec2(0.5, 0.5);
    particlecolor = color;
}
片段着色器

    #version 330 core

// Interpolated values from the vertex shaders
in vec2 UV;
in vec4 particlecolor;

// Ouput data
out vec4 color;

uniform sampler2D myTextureSampler;

void main(){
    // Output color = color of the texture at the specified UV
    color = texture2D( myTextureSampler, UV ) * particlecolor;

}

好吧,我把PMV矩阵搞砸了。它正在工作:请您详细说明一下好吗?当然可以:gl.glUniformMatrix4fvViewProjMatrixID,1,false,cam.MVMatrix;这部分实际上应该是这样的:gl.gluniformmatrix4fvviewprojmatrix,1,false,cam.PMVMatrix;我正在传递投影模型视图矩阵,但事实并非如此,我当时正在进行实验。问题出在摄像头代码中,PMVMatrix计算不正确。问题出在摄像头代码中,PMVMatrix计算不正确。我使用glGetFloatv检索ModelView矩阵和投影矩阵,然后计算PMV矩阵。我在那里输入了一个错误,并将投影矩阵分配给PMV矩阵,然后将空投影矩阵缓冲区与ModelView矩阵相乘,并将其结果分配给PMV矩阵。谢谢。现在更容易理解了。