Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TCL3D problem with drawing multiple objects

52 views
Skip to first unread message

Hans Nikolaus Beck

unread,
Jul 30, 2022, 4:10:20 PM7/30/22
to
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
}

But only the second object (here Triangle) is drawn. I've read many tutorials and examples, I can not see what's my mistake.
Do you see any wrong thing?

Thanks and Cheers

Hans

Hans Nikolaus Beck

unread,
Jul 31, 2022, 4:55:21 AM7/31/22
to
I've found the solution by myself. I've forgot to do the block

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

for *every* VAO/VBO object.

Cheers

Hans
0 new messages