3D spheres and adding textures in OpenGL - c++

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/

Related

Creating OpenGL Shadows

Does anyone know a good place to learn how to implement shadows in openGL? Or does anyone know how to do this? I know it isn't built into openGL by default but I can't seem to find any good examples. I've created a cube sitting on top of a plane in which I'm going to test this. I've created the cube and plane using:
glBegin(GL_QUADS);
to create a flat plane as well as a six sided cube that sits on that plane.
Creating shadows is an advanced technique (well, there are at least 3 methods applicable in your case). Before even attempting to do so, you need a firm grasp of OpenGL and it's concepts.
OpenGL is not a scene graph, it's a drawing API, so the idea is to combine drawing operations in a way, that you'll end up with what looks like correct shadows.
You may want to look up the topics:
Shadow Buffers
Stencil Volume Shadows
Planar Projection Shadows
Each finds tons of Google results. Add OpenGL to the seach term and you'll get numerous tutorials for each.

Drawing a simple anti-aliased stickman in OpenGL

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.

3D Lighting (OpenGl)

I already asked this question but I didn't get my answer. Btw I found some thing new.I want to show a 3D model from a wrl file exported by solid works.The file contains triangle's vertices and I am drawing them with glBegin(GL_TRIANGLES), But it doesn't looks nice and doesn't seems quite 3D! I tried gluSphere to draw an sphere in that scene with same lighting setting and it seems very nice and 3D!!!!
Is there some thing about Glu ?
Should I use Glu for draw triangles?
To get a good shading you should also supply normals for the triangles.

OpenGL texture mapping to already projected shape?

Newbie to OpenGL...
I have some very simple code (non OpenGL) for rotating a rectangle around a single axis, and projecting the result down to screen coordinates. I'm now trying to map a bitmap to the resulting shape using OpenGL. When animating the rotation, the perspective of the bitmap is quite heavily distorted. Is this to be expected? Is there something I can do about it?
I know I can use OpenGL to do the whole thing instead (and that works fine), but for my current project the approach above would suit me better, if I can just get around this perspective issue... I'm thinking maybe there's not enough information after I have projected the rotated rectangle down to 2D space for OpenGL to correctly map the bitmap with the right perspective..?
Any input would be much appreciated.
Thanks,
Daniel
To clarify:
I'm using an orthographic projection, and doing the 3D calculation and projection to 2D myself. Then I just use OpenGL for rendering the resulting shape with a texture.
If you project your coordinates yourself and do the texture mapping in 2D screen coordinates you will loose all projective information and the textures will badly distort.
You can get around this by using a perspective texture mapping. A lot of different ways to do this exist. Either by writing a real perspective texture mapper or by faking and using a plain texture mapper.
Explaining how this works is somewhat beyond the scope of a single question. I assume you read the wiki-page about perspective texture mapping first and try out the subdivision method:
http://en.wikipedia.org/wiki/Texture_mapping
Then come back and ask for detail questions..
I found the following page that explains the subdivision method in detail:
http://freespace.virgin.net/hugo.elias/graphics/x_persp.htm
It worked perfectly! Thanks Nils for pointing me in the right direction.

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