I am pretty new to godot and using this code to draw a quad. The quad does not appear in godot but it does appear in my own written opengl engine. Am I missing a step in godot?

*The flag on line 57 has been removed in the code that I try to run with no effect.

Welcome to the forums @Jakibah!

The code looks like it should work, at least based on my experience. The only thing I'm not sure on is the st.commit line, as I think the function returns the committed mesh. I would perhaps try seeing if t_mesh = st.commit(t_mesh, 256&1) fixes the issue.

@TwistedTwigleg Thank you for welcoming me!

Sadly enough that solution did not solve my problem.

Hi,

I never used SurfaceTool, but I see one thing that may cause issue when I checked documentation.

57 line shouldn't be changed to: st.commit(t_mesh, 256 | 1)?

When using 256 & 1 it mean you don't supply anything (because 256 & 1 is actually 0).

Also instead of numeric values I would use enum (like Mesh.ArrayFormat.ARRAY_FORMAT_VERTEX), but that is only suggestion.

Edit: I missed that information:

@Jakibah said: *The flag on line 57 has been removed in the code that I try to run with no effect. That mean you tried also without setting flags at all or setup flags differently? Default flags still may cause issues, because they assume a lot more data will be supplied.

It looks like you had a little typo where your last vertex is the same as your first, you probably meant Vector3(-0.5, 0, 0.5) for that one. I modified your code to the following and this seems to draw a quad as intended:


var a:PoolIntArray = [0, 1, 3, 1, 2, 3]

vertices.append(Vector3(0.5, 0.0, 0.5))
vertices.append(Vector3(0.5, 0.0, -0.5))
vertices.append(Vector3(-0.5, 0.0, -0.5))
vertices.append(Vector3(-0.5, 0.0, 0.5))

var st := SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)

for index in a:
	st.add_index(index)

for vertex in vertices:
	st.add_vertex(vertex)

self.mesh = st.commit()

@Azedaxen said: It looks like you had a little typo where your last vertex is the same as your first, you probably meant Vector3(-0.5, 0, 0.5) for that one. I modified your code to the following and this seems to draw a quad as intended:


var a:PoolIntArray = [0, 1, 3, 1, 2, 3]

vertices.append(Vector3(0.5, 0.0, 0.5))
vertices.append(Vector3(0.5, 0.0, -0.5))
vertices.append(Vector3(-0.5, 0.0, -0.5))
vertices.append(Vector3(-0.5, 0.0, 0.5))

var st := SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)

for index in a:
	st.add_index(index)

for vertex in vertices:
	st.add_vertex(vertex)

self.mesh = st.commit()

Using this code 4 points appear when I use PRIMITIVE_POINTS but they do not connect when triangles is chosen.

@Jakibah said: Using this code 4 points appear when I use PRIMITIVE_POINTS but they do not connect when triangles is chosen.

I did also notice that the winding order on these verts is such that the triangles face down towards -Y. If your camera is viewing them from the top-down, then you won't be able to see the triangles due to backface culling. If you intended for the triangles to face up towards +Y, then the correct winding order would be this: var a:PoolIntArray = [3, 1, 0, 3, 2, 1]

2 years later