Drawing a simple anti-aliased stickman in OpenGL - c++

I would like to draw a simple 2D stickman on the screen. I also want it to be anti-aliased.
The problem is that I want to use a bones system, which will be written after I would know how to draw the stickman itself based on the joints positions. This means I can't use sprites - I want my stickman to be fully controlable in the code.
It would be great if it will be possible to draw curves too.
Drawing a 3D stickman using a model would also be great if not better. The camera will be positioned like it's 2D, but I would still have depth. The problem is that I only have experience in Maya, and exporting and vertex weighting of the model in OpenGL seems like a mess...
I tried to find libraries for 2D anti-aliased drawing or enable multi-sampling and draw normally, but I had no luck. I also tried to use OpenGL's native anti-aliasing but it seems deprecated and the line joins are bad...
I don't want it to be too complicated because, well, it shouldn't be - it's just the first part of my program, and it's drawing a stickman...
I hope you guys can help me, I'm sure you know better than me :)

You could enable GL_SMOOTH. To check if you device supports your required line width for smooth lines, you can use glGet(GL_SMOOTH_LINE_WIDTH_RANGE);
If you want your code to be generic, you can also use antialiased textures.
Take a look at this link
http://www.opengl.org/resources/code/samples/advanced/advanced97/notes/node62.html

The only way to get antialiasing is use GL library which knows how to get antialiased GL context, for example, SDL. As of stickman, you can draw him with colored polygons.

Related

OpenGL: drawing lightning source

I am in front a simple issue, but I can't find a way to solve it:
I have the coordinates of a lightning source. I would like to draw a white circle centered on this lightning source.
How can I do that? Is there a opengl function or I should add manually verteces to create a circle?
Thanks
OpenGL does not have primitives like circles. It only has triangles, fundamentally.
Your best options are either to make a regular n-gon where n is large enough to satisfy you, or make the circle geometry part of a texture, and just render a square where some of the coordinates are transparent.
Which is most appropriate depends entirely on context.
Use Blender to create a simple circle mesh. Export to one of the available object files, load it in your app and render. You can use Assimp to load the mesh or write your own loader. You can find a lot of examples online on how to do this.

Query about TTF and OpenGL

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.

3D spheres and adding textures in OpenGL

I have been asked to do 3D sphere and adding textures to it so that it looks like different planets in the Solar System. However 3ds max was not mentioned as mandatory.
So, how can I make 3D spheres using OpenGL and add textures to it? using glutsphere or am I suppose to do it some other method and how to textures ?
The obvious route would be gluSphere (note, it's glu, not glut) with gluQuadricTexture to get the texturing done.
I am not sure if glutSolidSphere has texture coordinates (as far as I can remeber they were not correct, or not existant). I remember that this was a great resource to get me started on the subject though:
http://paulbourke.net/texture_colour/texturemap/
EDIT:
I just remembered that subdividing an icosahedron gives a better sphere. Also texture coordinates are easier to implement that way:
see here:
http://www.gamedev.net/topic/116312-request-for-help-texture-mapping-a-subdivided-icosahedron/
and
http://www.sulaco.co.za/drawing_icosahedron_tutorial.htm
and
http://student.ulb.ac.be/~claugero/sphere/

OpenGL, remove sections from a shape

In OpenGL, how can one cut a triangle shaped hole from a square? making the hole transparent.
I'm also using SDL, maybe it can be achieved with an SDL surface?
While doing it on a texture is truly the easier way out, if you need it to be a real shape, you might try using the GLUtesselator from GLU toolkit. See a tutorial for it here.
General usage is that you create a tesselator object, create two contours (the outer and the inner in a reverse direction) and the tesselator translates that into pure OpenGL commands. Of course if it's efficiency you're seeking you should implement or find some higher order system that operates on vertex buffers.
You can use a texture and alpha blending: the texture would contain a transparent triangle. See this tutorial on blending.
EDIT: Of course alpha blending doesn't change the geometry. For that you need to perform treatments that are more complicated. See this tutorial on realtime CSG.
Reference: Constructive Solid Geometry

How do I give GLUT cubes different colors?

Just what it says: I have some code that's drawing GLUT cubes, but they're all grey. How do I make them different colors?
Everything I've tried so far has failed. I think my problem is that I'm trying to use OpenGL functions to change their colors, but GLUT is maintaining it's own internal color or material data and I don't know how to make it change that data.
This is just filler graphics for a test-client for an online game, so they don't have to look good, I just need to be able to tell things apart. I know GLUT isn't considered great, so if anyone wants to post an example of drawing a cube with plain OpenGL instead of glutCube I'm all ears. I don't really care how I get the cubes on the screen, and it's not a part of the code I want to spend a lot of time on. I have a partner who's doing the real graphics; I just need to get something showing so that I can visualize what my code is doing.
The language I'm using OpenGL/GLUT from is called Io, but the API it exposes should be the same as if I were calling it from C.
It turns out that if I just do:
glEnable(GL_COLOR_MATERIAL)
then it makes the material track whatever color I set with glColor, even when lighting is enabled.
Just set the color beforehand with glColor(). If you're using lighting (i.e. GL_LIGHTING is enabled), though, then you'll instead have to use glMaterial() to set the cube's color.