Orthographic projection of a sphere to get a circle (OpenGL -- newbie) - opengl

I am trying to draw a very simple, black and white stick figure whose head is a sphere. The background is black and I am drawing with white color. The orthographic projection of the sphere head should be a white circle with line width of 3 pixels. Everything behind the head should be hidden (DEPTH_TEST enabled). I would like to avoid using glut but glu is OK.
What is the simplest way to achive this?

Not using a sphere. A sphere will be composed of several triangles, and if drawn using a line mode you'll end up with a wireframe sphere. Silouhette Shaders are overkill here. The simplemost solution is drawing a line circle, that's oriented towards the camera (=origin), i.e. a billboard effect.

If you really want to use a sphere and orthographic projection I recommend looking at gluSphere.
An alternative would be gluDisk (which already is 2D).
However, for pure 2D graphics (as it sounds) I recommend that you think about using point-sprites for the circles: One Quad with the circle as texture
http://nehe.gamedev.net/data/articles/article.asp?article=19

Related

OpenGL selection area

I'm currently using LWJGL but if you have a solution for OpenGL I can use that too.
Now, I'm trying to apply a selection area to a plane that I can move around with my mouse (like my terrible drawing above). I'm trying to make it flat to the plane, so it can move over any obstacles. I've considered projection texture but I dont know how to implement it. Is this a good way of solving the problem or is there any better alternative?
What would be the best way to implement a selection area?
Alternative options, pros and cons.
Edit: This will be moving over another texture if that makes a difference.
When you already know the intersection point in world space, there is a relative simple solution that doesn't require projected textures:
In the fragment shader calculate the world-space distance between the intersection point and the current fragment. When the distance between the two is smaller than the desired radius of the circle, then the selection color should be drawn. Otherwise just the normal plane is drawn.
float dist = length(current_ws - intersection_ws);
if (dist < circle_radius)
//Draw overlay
else
//Draw plane normal

OpenGL - skybox and frustum clipping

I want to create skybox, which is just textured cube around camera. But actually i don't understand how this can work, because the camera viewing volume is frustum and the skybox is cube. According to this source:
http://www.songho.ca/opengl/gl_projectionmatrix.html
Note that the frustum culling (clipping) is performed in the clip
coordinates, just before dividing by wc. The clip coordinates, xc, yc
and zc are tested by comparing with wc. If any clip coordinate is less
than -wc, or greater than wc, then the vertex will be discarded.
vertexes of skybox faces should be clipped, if they are outside of frustum.
So it looks for me that the cube should be actually a frustum and should match exactly the gl frustum faces, so my whole scene is wrapped inside of that skybox, but i am sure this is bad. Is there any way how to fill whole screen with something, that wraps whole gl frustum?
The formulation from your link is rather bad. It is not actually vertices that get clipped, but rather fragments. Drawing a primitive with vertices completely off-screen does not prevent the fragments that would intersect with the screen from getting drawn. (The picture in the link also actually shows this being the case.)
That having been said, however, it may (or may not, depending on the design of your rendering code) be easier to simply draw a full-screen quad, and use the inverse of the projection matrix to calculate the texture coordinates instead.

how to draw polygons in OpenGL that have an outline drawn with a black pen and another fill color

How can I draw a shape like this in OpenGL?
I mean, I know how to draw polygons in OpenGL. I want to know how to make the outline black and the fill color ( for example ) yellow?
You have 5 vertices. Draw a GL_POLYGON with them and then then a GL_LINE_LOOP.
Note that GL_POLYGON is only valid for convex polygons.
I would cheat. I would create the polygons in a 3d suite as meshes, and create different meshes for the borders. And then draw first the polygon and then the border, using the same transforms, with glDepthFunc(GL_LEQUAL).
In this way you can also give the border a nice outfit: you could make them look as if they were drawn by a pen, or sketched with a pencil or whatever. Also, this solution is good to go with modern OpenGL, while using GL_POLYGON is not .

OpenGL 360 degree perspective

I'm looking to capture a 360 degree - spherical panorama - photo of my scene. How can I do this best? If I have it right, I can't do this the ordinary way of setting the perspective to 360.
If I would need a vertex shader, is there one available?
This is actually a nontrivial thing to do.
In a naive approach a vertex shader that transforms the vertex positions not by matrix multiplication, but by feeding them through trigonometric functions may seem to do the trick. The problem is, that this will not make straight lines "curvy". You could use a tesselation shader to add sufficient geometry to compensate for this.
The most straightforward approach is two-fold. First you render your scene into a cubemap, i.e. render with a 90°×90° FOV into the 6 directions making up a cube. This allows you to use regular affine projections rendering the scene.
In a second step you use the generated cubemap to texture a screen filling grid, where the texture coordinates of each vertex are azimuth and elevation.
Another approach is to use tiled rendering with very small FOV and rotating the "camera", kind of like doing a panoramic picture without using a wide angle lens. As a matter of fact the cubemap based approach is tiled rendering, but its easier to get right than trying to do this directly with changed camera direction and viewport placement.

Circle on non plane surface in opengl

I need to draw a circle on some arbitrary non plane surface, but this circle should lay on surface and follow surface's irregular form. In other words ( that is actuially can be one of possible solutions) want to have a "shadow" like projection on non plane surface near the mouse pointer. Do I need to create in memory a sphere and project it on the surface ? Are there some other techniques to achieve the same goal?
Thank you in advance.
There are two ways to do this. First would be, to create a cylinder and intersect it with the surface, get the intersection segments, and draw them. If you already have a math library which you can leverage, and if you don't have to do intersections every frame, then this might be a good idea. You will get accurately what you want.
The other option, as you already suggested would be to use a projection. I am not sure though that, you will be able to see clearly the shadow of a circle on a surface. If however, you have parametric texture coordinates for your surface, you can create a texture with the circle imprinted on it, and apply this texture to the surface.