Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to draw triangles or polygons? #8

Open
rh12503 opened this issue Oct 20, 2020 · 8 comments
Open

Is it possible to draw triangles or polygons? #8

rh12503 opened this issue Oct 20, 2020 · 8 comments

Comments

@rh12503
Copy link

rh12503 commented Oct 20, 2020

Looking at the source code, there doesn't seem to be any way to draw triangles or polygons.

Is there any way to access lower-level functions to achieve this, or is this being planned for a future update?

Thanks!

@gonutz
Copy link
Owner

gonutz commented Oct 20, 2020

Until now I have had no plan to include polygons. I could, though. What is your use case?

@rh12503
Copy link
Author

rh12503 commented Oct 21, 2020

Thanks for your fast reply! I've been experimenting with a visual effect that uses triangles, and I've really enjoyed using this library so I thought I would start here. It's not too important though, and I'm sure I could find some workarounds on my own.

@rh12503
Copy link
Author

rh12503 commented Oct 21, 2020

I managed to add my own FillTriangle and DrawTriangle functions to a copy of this library, so my issue is solved. It still would be cool to have a polygon function, but I'm not sure if that would be in line with this project's vision.

@gonutz
Copy link
Owner

gonutz commented Oct 21, 2020

I think that actually a DrawPolygon and FillPolygon function would be nice to have. It would increase the API size by two functions which is OK for the benefit it brings in my opinion. I am currently spending my free time on the wui library (it gets a graphical GUI designer) but when I get around to it I will look into implementing this. The main problem will be that the SDL2 backend does not support drawing triangles if I remember correctly. For the DirectX and OpenGL backends it will be no problem.

Can you share your version of the code?

@rh12503
Copy link
Author

rh12503 commented Oct 22, 2020

I couldn't get SDL2 working on my system, but I'm pretty sure it should be able to draw triangles. Here's my code for GLFW:

func (w *window) DrawTriangle(x0, y0, x1, y1, x2, y2 int, color Color) {
	gl.Begin(gl.LINE_STRIP)
	gl.Color4f(color.R, color.G, color.B, color.A)
	gl.Vertex2f(float32(x0)+0.5, float32(y0)+0.5)
	gl.Vertex2f(float32(x1)-0.5, float32(y1)+0.5)
	gl.Vertex2f(float32(x2)-0.5, float32(y2)-0.5)
	gl.Vertex2f(float32(x0)+0.5, float32(y0)-0.5)
	gl.End()
}

func (w *window) FillTriangle(x0, y0, x1, y1, x2, y2 int, color Color) {
	gl.Begin(gl.TRIANGLES)
	gl.Color4f(color.R, color.G, color.B, color.A)
	gl.Vertex2i(int32(x0), int32(y0))
	gl.Vertex2i(int32(x1), int32(y1))
	gl.Vertex2i(int32(x2), int32(y2))
	gl.End()
}

@sadek69
Copy link

sadek69 commented Mar 17, 2021

Hi very good and easy for use engine,how use different colour exclude this predefined colors?

@gonutz
Copy link
Owner

gonutz commented Mar 17, 2021

There are functions draw.RGB(r, g, b float32) and draw.RGBA(r, g, b, a float32) which take color channel values in the range 0.0 .. 1.0.

@sadek69
Copy link

sadek69 commented Mar 17, 2021

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants