I'm trying to render an unfilled circle in OpenGL that works with batching. Using GL_LINE_LOOP works, but when I put all vertices inside a batch to render at once, a straight line from one circle is drawn to the next. I couldn't find any good solution other than not to use GL_LINE_LOOP. Same with filled circles, I had to change from GL_TRIANGLE_FAN to GL_TRIANGLES and create vertices in little triangles from center of the circle and two connected points on the outer part of the circle. However, I'm trying to use GL_LINES and have two vertices that create a line, then add the last vertex again along with the next one. But I can't seem to get it to work and I end up with gaps inside the circle.
I can't find much online about drawing unfilled circles that work with batching. I'm using Pyglet as a framework for batching and rendering.
Related
I'm able to draw a simple cube with modern opengl, but I would like to be able to draw a line cube from the same data I draw my current cube with (vertices):
currently I'm drawing a cube and using glPolygonMode to draw the lines, but I would like to get rid of the lines going though each quad face (essentially just drawing the edges of the cube)
I wasn't able to get any further than this, I don't know how to tackle this topic (shaders, or some other opengl method)
how can I draw a cube in such a way?
Easiest way is to still use glPolygonMOde(...) while rendering QUADS instead of TRIANGLES. This however requires change in your data ...
In case your meshes will be always composed from QUADS and triangulated so the 2 consequent triangles always form a QUAD but you are unwilling to switch to QUADS then you can write a Geometry shader taking in 6 Vertexes and outputting 4 lines which will be still more or less "fast" however note that Geometry shaders where not very reliable in past...
If those are not an option you can modify this:
Silhouette-Outlined shader
To render fragments near sharp normal changes. However this will hide back sides so in order to have them too you have to do this in 2 passes one with glFrontFace(GL_CW); and the other with glFrontFace(GL_CCW); combining their outputs. This also allows you to set different color to the hidden edges ...
So I see it like this:
glFrontFace(GL_CW);
render_mesh_to_trexture(); // using normal instead of color
render_siluete_from_texture(); // using texture from previous line
glFrontFace(GL_CCW);
render_mesh_to_trexture(); // using normal instead of color
render_siluete_from_texture(); // using texture from previous line
However this will be a lot slower and requires consistent winding rule...
Another option is to just compile list of edges from your mesh on CPU side and remove all that have duplicates. Its simple and fast however will create new VBO/VAO data and no longer complies with your requirement to use the same data (however the new VBO might be just integer indices so 2 ints per edge).
I know two ways of drawing a circle: circle that contains of GL_LINES or contains of flat triangles (GL_TRIANGLES). In the second case we need to store more vertices and display it every frame. But triangles better to use in tearms of performance of the GPU.
So what's better to use when you need to draw many circles on the screen? Lines or flat triangles?
It could be that lines are being drawn with the help of triangles. You can check it by switching fill mode to wireframe.
I'm making a 2D game that uses directx. Currently, I have a background texture (with more to come) that I draw to the screen. However, I only want a portion of the texture drawn to the screen. I know that I could use a rectangle with the draw function, but I need a greater degree of control. Is there a way to draw several triangles (using custom vertices) to the screen from my drawing? I've looked around the internet and this site, but I just can't seem to find what I want. I can give more information/code if needed. Thank you!
I need to draw a load of cubes and would like them to be white with black stroke. At the moment I am storing all of these cubes in a VBO and I can draw them in wireframe and filled with no outline.
I would like to draw them like the image on the left in this image, stroked only on the sides facing the camera, not like the right.
I am using OpenGL.
What you want is to remove hidden lines.
If you want to draw a wireframe object with hidden lines removed, one approach is to draw the outlines using lines and then fill the interiors of the polygons making up the surface with polygons having the background color.
You need to glEnable(GL_CULL_FACE); in order to get back-face culling of triangles not visible automatically applied. Provided the "winding order" of your triangles is consistent of course (clockwise or anti-clockwise). If they're wound in the opposite direction, you can tell OpenGL which direction to use with glFrontFrace(GL_CW | GL_CCW) and whether to cull front or back facing triangles with glCullFace(GL_BACK | GL_FRONT).
When you draw a line in OpenGL, glLineWidth creates a fixed-size line, regardless how close the line is to you.
I wanted to draw a line that will appear bigger when it's close. Now, I understand that if I use a rectangle to achieve this effect, it will look a bit pixelated once the polygon is far enough.
What I've previously done is to draw a normal GL_LINE up to the point where the line would get bigger than the pixel size, and then continue with a rectangle from that point. However, it's not as fast as just chucking everything down to a vertex array or VBO, as it had to be recalculated every frame.
What other methods are available? Or am I stuck with this?
I like to use a gradated texture like this to draw lines:
This is really the alpha of my texture. So you have a fully opaque center fading to fully transparent at the edges. Then you can draw your line using a rectangle with points:
(x1,y1,0,0), (x2,y1,1,0), (x1,y2,0,1), (x2,y2,1,1)
where the last two entries in each tuple are u and v of the texture. It ends up looking very smooth. You can even string together lots of very small rectangles to make curvy lines.
If you're just drawing a bunch of lines and want a quick and easy depth effect try adding fog. The attenuation of the lines as they recede makes our brains think they're 3d. This isn't going to work if the near ends are really close to the viewer.
If you want your lines be thicker on near end and thinner on far end, I suppose you have to model them from polygons.