# Thread: Drawing multiple circles in OpenGL

1. ## Drawing multiple circles in OpenGL

Hi all,

I am fairly new to the world of OpenGL, and I am trying to draw a few circles in 2D. These circles are static right now, but will start moving later on. I can't seem to get it to work and I would really appreciate some help here.
Here's what I have so far:

1. I create a vector of vertices for a generic circle centered at (0,0) of radius 1:

Code :
```const size_t nVertices = 100;
float vertices[3*nVertices];
const float twoPi = 8.0f*atan(1.0f);
const size_t nSides = nVertices-2;
for (size_t i = 1; i < nVertices; i++)
{
vertices[3*i  ] = cos(i*twoPi/nSides);
vertices[3*i+1] = sin(i*twoPi/nSides);
vertices[3*i+2] = 0.0f;
}```

These vertices are pushed to the GPU before entering the time loop.

2. I create a bunch of circles with a given location and radius. Note that these are defined in world coordinates (x and y from 0 to 2000). I would like to fit the entire world into my square window. Hence, I have two uniforms for the mapping:

Code :
```shader.use();

3. In the display function, I have:

Code :
```shader.use();
glBindVertexArray(vao);
for(const auto circle : circles) {
glDrawArrays( GL_TRIANGLE_FAN, 0, nVertices);
}```

4. Finally, the vertex shader is as follows:

Code :
```#version 330 core
layout (location = 0) in vec3 aPos;
uniform vec3 location;
uniform float worldScreenRatio;
uniform vec3 shiftWorldCenter;

void main()
{
gl_Position = vec4(worldScreenRatio*vec3(radius*aPos + location + shiftWorldCenter), 1.0);
}```

I created 3 circles in the corners of my world (1900,1900), (100, 1900) and (100, 100) and tried to display them. Unfortunately, I am getting this strange results instead of my circles (see attached figure).

Am I missing something? It seems to work just fine when I don't use the worldScreenRatio and specify locations between -1 and 1. I don't understand what I am doing wrong here.

Thank you for your help, please let me know if you need extra information regarding this case.

Joachim

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•