Hello Guest

Recent Posts

Pages: 1 ... 6 7 [8] 9 10
OpenGL / Re: Per mesh model matrices
« Last post by Mihai_Ionut_Floares on December 01, 2020, 10:41:59 »
Thank you. My question is How game engines like unity that uses DirectX allow you to specify a HLSL program for each a material that you later assign that material to the object?
OpenGL / Re: Per mesh model matrices
« Last post by KaiHH on December 01, 2020, 10:35:59 »
1. bind shader
2. upload matrix for object 1
3. draw object 1
4. upload matrix for object 2
5. draw object 2

No need for a separate shader program. All you need is to update the model matrix (or model-view-projection combination matrix) for each model.

This is, however, the most unoptimal way to do it. You could also use a uniform buffer object to store all objects' model matrices and then lookup the respective matrix needed for a particular object via a vertex attribute that you advance per object.
This would allow you to draw all objects (capped by the maximum UBO size, of course) with a single draw call.

There are many more possibilities, such as using instancing and storing only the individual objects' translations as instanced vertex attributes (in case where the objects' transformations only differ in translation and not e.g. in rotation and scaling).
OpenGL / Per mesh model matrices
« Last post by Mihai_Ionut_Floares on December 01, 2020, 10:20:43 »
I figured out the movementof the camera trough scene and the perspective/view/model matrices that I created from scratch sine I didn't want to use JOML. It is working: https://streamable.com/1exa27

But now I want to add another mesh, but the meshes share the same model matrix. The projection and view matrices should be the same, but the model should be different because when I translate one object, all meshes are translated. The matrices are sent to vertex shader, but I can't figure out how to make per mesh model matrices. I guess I need per mesh shaders???
OpenGL / Re: glDrawArrays causes coredump with SIGSEGV
« Last post by mikem on November 28, 2020, 15:14:07 »
OMG. That's embarrasing  :-[ Probably just choosen a wrong auto-complete item and it costed me hours of wondering.

Thank you! I see the triangle now. Also noted the glEnableVertexAttribArray remark. Thanks!
OpenGL / Re: glDrawArrays causes coredump with SIGSEGV
« Last post by KaiHH on November 28, 2020, 14:49:57 »
The error is with the call:
Code: [Select]
glVertexAttribPointer(0, 3, GL_FLAT, false, 0, 0);
This call is generating an OpenGL error (and its effect is therefore ignored), because you pass the invalid constant `GL_FLAT`. It should be `GL_FLOAT`.
This causes glDrawArrays() to access undefined memory (because the vertex buffer has not been specified as the vertex attribute source).

Besides that:
Code: [Select]
can be executed within the VAO binding just once in start(). Vertex array enable state is part of the VAO and you don't have to enable/disable constantly.
OpenGL / glDrawArrays causes coredump with SIGSEGV
« Last post by mikem on November 28, 2020, 14:29:45 »
I'm loosely following this tutorial https://lwjglgamedev.gitbooks.io/3d-game-development-with-lwjgl/content/chapter04/chapter4.html to get familiar with lwjgl and OpenGL. The goal is to just get this simple triangle on screen but my code keeps on crushing on glDrawArrays call with coredump and SIGSEGV. Looks like OpenGL can't get access to the vbo data created but I can't see what and where could go wrong with that.

Code: [Select]
import org.lwjgl.glfw.GLFWErrorCallback;

import org.lwjgl.opengl.GL;

import java.nio.FloatBuffer;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.system.MemoryUtil.*;

public class Main {
    private long window;
    private ShaderProgram shaderProgram;
    private int vaoId;

    public void start() {

        if (!glfwInit())
            throw new IllegalStateException("Error");


        glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE);
        glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

        window = glfwCreateWindow(1920, 1080, "OpenGL", NULL, NULL);

        if (window == NULL)
            throw new RuntimeException("Couldn't create a window");

        glfwSetKeyCallback(window, (window, key, scancode, action, mode) -> {
            // TODO





        shaderProgram = new ShaderProgram();
        shaderProgram.attachShader(new Shader(Res.string("fragment.frag"), GL_FRAGMENT_SHADER));
        shaderProgram.attachShader(new Shader(Res.string("vertex.vert"), GL_VERTEX_SHADER));

        float[] verts = new float[]{
                0.0f, 0.5f, 0.0f,
                -0.5f, -0.5f, 0.0f,
                0.5f, -0.5f, 0.0f

        FloatBuffer vertBuffer = memAllocFloat(verts.length);

        vaoId = glGenVertexArrays();

        int vboId = glGenBuffers();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, vertBuffer, GL_STATIC_DRAW);

        glVertexAttribPointer(0, 3, GL_FLAT, false, 0, 0);

        glBindBuffer(GL_ARRAY_BUFFER, 0);

        glViewport(0, 0, 1920, 1080);
        glClearColor(1.f, 0.f, 1.f, 1.f);


    void loop() {
        while (!glfwWindowShouldClose(window)) {



            glDrawArrays(GL_TRIANGLES, 0, 3);




    public static void main(String[] args) {
        new Main().start();

All the shader stuff seem to be working fine. But in case it can be relevant here's the gist with the rest of the code including shaders: https://gist.github.com/miriti/c578f4f4c000a4a84f1af260fa4ba28e
Lightweight Java Gaming Library / Eclipse Import Suggestions (Issue)
« Last post by ZackTactical34 on November 26, 2020, 02:19:15 »
I'm facing a weird issue with import suggestions not showing on Eclipse. I followed this tutorial and seem to have everything set up correctly: https://www.youtube.com/watch?v=oHyzjnhqjpc&start=314s

The code will work, but it's a pain to have to type out each import statement. Please let me know if there is a fix (I'm guessing there is and I'm just not seeing it).
Lightweight Java Gaming Library / Re: Project panama
« Last post by tlf30 on November 20, 2020, 03:31:24 »
I see that Panama will be included as a preview in JDK 16. Exciting to see it finally making it into a JDK!
OpenGL / Re: I'm unable to properly blend z-ordered textures
« Last post by KaiHH on November 19, 2020, 08:04:00 »
You could always use texture atlases (pack multiple images into the same texture and assign texture coordinates accordingly) or use array textures, where each layer is a different image and index into the corresponding layer in the fragment shader.
OpenGL / Re: I'm unable to properly blend z-ordered textures
« Last post by noncompetitive_antagonist on November 19, 2020, 02:08:28 »
 :) Thank you. I suppose I'll have to render by z-index; hopefully, switching between 2d sprite textures won't be too performance intensive.
Pages: 1 ... 6 7 [8] 9 10