Draw circle in child-window with OpenGL

I have an Eclipse program with a child-window inside a window. I can use OpenGL in Eclipse. How to draw a circle inside a child-window using OpenGL?
bchinfosieeuw, what version of OpenGL are you adhering to? I was tempted to post salem c's answer as well... but it doesn't help that the first result on that query is the old, immediate-mode OpenGL, so I'll try to give a modern alternative.

First step before drawing a circle is to draw a triangle. Because in graphics, everything is triangles. Even circles.

If you're new to modern opengl, visit: http://www.opengl-tutorial.org/

The second tutorial talks about how to draw a triangle.
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/
1
2
3
4
5
6
// An array of 3 vectors which represents 3 vertices
static const GLfloat g_vertex_buffer_data[] = {
   -1.0f, -1.0f, 0.0f,
   1.0f, -1.0f, 0.0f,
   0.0f,  1.0f, 0.0f,
};


The difference for a circle is, you're going to have a lot more vertices. Imagine a circle as actually being a bunch of small slices of pie, each slice being a thin triangle. The thinner each slice, the smoother the circle will look.

You can generate the vertices for a triangle by using trig.
{ x = cos(t), y = sin(t), z = 0 }, and loop t from 0 to 2 Pi, equally spaced. Try to adapt the existing code in the tutorial to make a circle (modify g_vertex_buffer_data).

Be sure to update the call to glBufferData to give the correct size of the array (it will be bigger) and tell glDrawArrays to draw more vertices.

_____________________________________________

If the issue is specifically working with child windows, and not the circle shape specifically, that would depend on what windowing library you're using to make windows, and what that library's rules are for opengl contexts. The details of that can get hairy. I would search "[gui/window library you're using] opengl child window".
Last edited on
I am using the newest version of OpenGL and the windowing library is windows.h.
Topic archived. No new replies allowed.