• TCL3D - multiple Objects using VBO /VA=

    From Hans Nikolaus Beck@21:1/5 to All on Sat Jul 30 13:07:11 2022
    Hi
    with TCL3D I want to draw 2 simple objects. The init code is like this:

    proc Init {} {
    global g_Demo g_Program
    ...
    # Load the source of the vertex shader.
    set vertexSource [tcl3dOglReadShaderFile [file join $g_Demo(scriptDir) "Vertex02.vs"]]
    # Load the source of the fragment shader.
    set fragmentSource [tcl3dOglReadShaderFile [file join $g_Demo(scriptDir) "Fragment01.fs"]]

    set g_Program [tcl3dOglBuildProgram $vertexSource "" "" "" $fragmentSource]
    set program [dict get $g_Program program]

    # The location of the vertex in the shader program
    set vertexLocation [glGetAttribLocation [dict get $g_Program program] "vertex"]
    set g_Demo(projectionLocation) [glGetUniformLocation $program "projectionMatrix"]
    set g_Demo(modelViewLocation) [glGetUniformLocation $program "modelViewMatrix"]
    set g_Demo(colorLocation) [glGetUniformLocation $program "shapeColor"]

    # generate a circle
    set pointList [doCircles]
    set pointVec [tcl3dVectorFromList GLfloat $pointList]
    set pointVecSize [expr [llength $pointList] * [$pointVec elemsize]]

    # The VAO for the vertices etc.
    set g_Demo(vao) [tcl3dVector GLuint 1]
    glGenVertexArrays 1 $g_Demo(vao)
    glBindVertexArray [$g_Demo(vao) get 0]

    # The VBO for the vertices.
    set g_Demo(vertices) [tcl3dVector GLuint 1]
    glGenBuffers 1 $g_Demo(vertices)
    glBindBuffer GL_ARRAY_BUFFER [$g_Demo(vertices) get 0]
    glBufferData GL_ARRAY_BUFFER $pointVecSize $pointVec GL_STATIC_DRAW

    # the triangle
    set pointVecTg [tcl3dVectorFromList GLfloat $pointListTriangle]
    set pointVecSizeTg [expr [llength $pointListTriangle] * [$pointVecTg elemsize]]

    # The VAO for the vertices etc.
    set g_Demo(vaoTg) [tcl3dVector GLuint 1]
    glGenVertexArrays 1 $g_Demo(vaoTg)
    glBindVertexArray [$g_Demo(vaoTg) get 0]

    # The VBO for the vertices.
    set g_Demo(verticesTg) [tcl3dVector GLuint 1]
    glGenBuffers 1 $g_Demo(verticesTg)
    glBindBuffer GL_ARRAY_BUFFER [$g_Demo(verticesTg) get 0]
    glBufferData GL_ARRAY_BUFFER $pointVecSizeTg $pointVecTg GL_STATIC_DRAW

    glVertexAttribPointer $vertexLocation 4 GL_FLOAT GL_FALSE 0 "NULL"
    glEnableVertexAttribArray $vertexLocation
    glUseProgram [dict get $g_Program program]
    }

    and in the DisplayCallback :
    ...
    glBindVertexArray [$g_Demo(vao) get 0]
    glUniform4f $g_Demo(colorLocation) 1.0 1.0 1.0 1.0
    glDrawArrays GL_LINE_LOOP 0 72

    glBindVertexArray [$g_Demo(vaoTg) get 0]
    glUniform4f $g_Demo(colorLocation) 1.0 0.3 0.9 1.0
    glDrawArrays GL_TRIANGLES 0 3

    glFlush

    $toglwin swapbuffer
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)