I am currently drawing some geometry with "modern OpenGL" using QUAD and QUADSTRIP primitives.
I have faced with strange artifacts. My quads actually tessellates with visible triangles. Hope you'll see while lines across quads.
Any ideas?
Modern OpenGL (3.1+ Core Profile) does not support QUADS or QUADSTRIPS. Check for example here for allowed primitive types.
The culprit most likely is that you enabled polygon smooth antialiasing (still supported in compatibility profile), i.e. did glEnable(GL_POLYGON_SMOOTH) + some blending function. Artifacts like the one you observe are the reason, nobody really bothered to use that method of antialiasing.
However, it may very well be, that you did enable antialiasing in your graphics driver settings and the AA method used doesn't play along nicely with your program.
Related
First, some context :
The 3D engine I wrote for my game allows me to switch between DirectX 9 and OpenGL, thanks to an intermediate API layer.
Both allow the user to enable multisampling (via GL_ARB_multisample for OpenGL, D3DMULTISAMPLE_x_SAMPLES for DirectX). Multisampling is enabled for the game window buffer.
The models for my characters use one big texture with texture atlases, so I disabled mipmapping there in order to avoid texture bleeding.
I experience the following results :
As I should, I get the same result when disabling multi-sampling for DirectX or OpenGL.
As I should, I correctly get edge smoothing on polygons when enabling multi-sampling for both.
However, in OpenGL, it seems that multi-sampling also has an effect akin to texture filtering, probably multi-sampling at different spots in the texture for each pixel, as the results are comparable to what mipmap would achieve, without texture bleeding - obviously, great. On the other hand, however, DirectX doesn't seem to provide this benefit as the result of texture mapping isn't anti-aliased, and the same as when multi-sampling is disabled.
I would very much like to know if there is anything I can do in order to get the same result in DirectX as in OpenGL. Maybe I am not aware of the good keywords, but I haven't been able to find documentation that relates to this specific aspect of multisampling.
I have a transparent OpenGL texture which has some simple shapes drawn on it by OpenGL:
circles, polygons, lines. They are drawn without anti-aliasing, multi-sampling, etc. Therefore, they have jaggy borders.
I don't have access to process of texture creation so I cannot enable multi-sampling
.
Is there a way to make those smooth AFTER drawing is done?
There are image-based anti-aliasing filters such as FXAA and MLAA that will work in this situation. I hesitate to call them anti-aliasing because they do not really avoid aliasing, they just hide it after the fact. They are more akin to intelligent blur filters.
I know from your other question that you do not want to use FBOs, so that leads me to believe you are using an OpenGL 2.1 or older codebase. FXAA can be implemented in GLSL 1.20, but it works better in 1.30 (GL 3.0). The one thing I do not know about is using FXAA on an image that includes transparency, it expects luminance to be encoded in the alpha channel (or sRGB, which is not a GL 2.1 feature).
You will probably not want to apply FXAA to your texture directly, rather you would need to draw into a PBuffer and apply FXAA after you blend your input texture.
Is there equivalent functionality to Directx's texturing blending? http://msdn.microsoft.com/en-us/library/windows/desktop/bb206241(v=vs.85).aspx
It basically blends several textures together before applying it onto the mesh.
From scanning through that page, I believe you can do all of that in a fragment shader. You can bind multiple textures, sample them all in your shader, and combine the results at your hearts desire.
It looks similar to functionality that OpenGL used to have in the fixed function pipeline. My old version of the red book (OpenGL Programming Guide) has chapters on "Multitexturing" and "Texture Combiner Functions". This is still available if you use the compatibility profile. But IMHO, this is a great example of where squeezing certain kinds of functionality into the fixed pipeline looked very cumbersome, while doing the same thing in shaders is much easier and more flexible.
I searched around a bit and couldn't find anything clear cut as to whether/how you can render true-type fonts using OpenGL (with SDL as the API if it makes any difference).
So I was wondering if anybody with experience knows the answer to if it is possible and how, or could point me to some other good source or explanation.
If it's not possible which I suspect is the case, any other suggestions would be greatly appreciated for working with fonts using OpenGL.
OpenGL itself deals only with points, lines and triangles. Anything going beyond that functionality must be implemented by the user. So no, there's no direct support for font rendering in OpenGL.
One can of course use OpenGL to rasterize glyphs, by various methods.
A very widespread method is texture mapped fonts, i.e. each (used) glyph of a font rendered into a texture atlat.
One can use OpenGL primitives to raster glyph curves, though this is a tricky subject.
Use shaders to implement vector textures
Use shaders to implement distance maps (distance maps are not unlike texture mapped font's but with a greatly reduced memory footprint).
Look at this. Here is a more recent example of using FreeType with OpenGL.
I've been using OpenGL since some time now for making 3D applications, but I never really understood the use of the GL_POINT and GL_LINES primitive drawing types for 3D games in the production phase.
(Where) are point and line primitives in OpenGL still used in modern games?
You know, OpenGL is not just for games and there are other kind of programs than just games. Think CAD programs, or map editors, where wireframes are still very usefull.
GL_POINTS are used in games for point sprites (either via the pointsprite functionality or by generating a quad from a point in the geometry shader) both for "sparkle" effects and volumetric clouds.
They are also used in some special algorithms just when, well... when points are needed. Such as in building histograms in the geometry shader as by the chapter in one of the later GPU Gems books. Or, for GPU instance culling via transform feedback.
GL_LINES have little use in games (mostly useful for CAD or modelling apps). Besides not being needed often, if they are needed, you will normally want lines with a thickness greater than 1, which is not well supported (read as: fast) on all implementations.
In such a case, one usually draws thick lines with triangle strips.
Who ever said those primitives were used in modern games?
GL_LINES is critical for wireframe views in 3D modeling tools.
(Where) are point and line primitives in OpenGL still used in modern games?
Where do you want them to be used?
Under standard methods, points can be used to build point sprites, which are 2D flatcards that always face the camera and are of a particular size. They are always square in window-space. Sadly, the OpenGL specification makes using them somewhat dubious, as point sprites are clipped based on the center of the point, not the size of the two triangles that are used to render it.
Lines are perfectly reasonable for line drawing. Once upon a time, lines weren't available in consumer hardware, but they have been around for many years now. Of course, antialiased line rendering (GL_LINE_SMOOTH) is another matter.
More importantly is the interaction of these things with geometry shaders. You can convert points into a quad. Or a triangle. Or whatever you want, really. Each "point" is just an execution of the geometry shader. You can have points which contain the position and radius of a sphere, and the geometry shader can output a window-aligned quad that is the appropriate size for the fragment shader to do some raytracing logic on it.
GL_POINTS just means "one vertex per geometry shader". GL_LINES means "two vertices per geometry shader." How you use it is up to you.
I'd say for debugging purposes, but that is just from my own perspective.
Some primitives can be used in areas where you don't think they can be applied, such as a particle system.
I agree with Pompe de velo about lines being useful for debugging. They can be useful when debugging AI and collision detection algorithms so that you can visualize the data that is being used by the AI or collision detection. Some example uses for AI, the lines can be used to show AI paths or path meshes. Lines can be used to show steering data that the AI is using. Lines can be used to show what an AI is aiming at. The data that is shown can be displayed in text form but sometimes it is easier to see it in visual form.
In most cases particles are based on GL_POINT, considering that there can be a huge number of particles on the screen it would be very expensive to use 4 vertices per particle, so GL_POINT solves this problem
GL_LINES good for debugging purposes, wireframe mode can be used in various cases. As mentioned above - in CAD apps, but if you're interesed in gamedev use - it's good for a scene editor.
In terms of collision detection, they come in handy when you want to visualize bounding volumes(boxes,spheres,k-dops) and contact manifolds in wireframe mode. Setting the colour of these primitives based on the status of collisions as well is incredibly useful.