drawCircle sample code
#include <iostream>
// GLEW
#define GLEW_STATIC
#include <GL/glew.h>
// GLFW
#include <GLFW/glfw3.h>
// Window dimensions
const GLuint WIDTH = 800, HEIGHT = 600;
static void Initialize(void);
void RenderScene(GLFWwindow* window) {
//glRotatef((float)glfwGetTime() * 5.f, 0.f, 0.f, 1.f);
glBegin(GL_LINES);
glVertex2f(.25, 0.25);
glVertex2f(.75, .75);
glEnd();
glFlush();
}
void RenderCircle() {
int i;
int triangles = 180; // number of triangles
int a = 0.2;
int b = 0.2;
float twoPi = 2.0f * 3.14159f;
float radius = 0.5;
glPointSize(5);
//glBegin(GL_POINTS);
//glBegin(GL_LINE_STRIP);
//glBegin(GL_POLYGON);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(a, b); // origin
for (i = 0; i <= triangles; i++) {
float x = radius * cos(i * twoPi / triangles);
float y = radius * sin(i * twoPi / triangles);
glVertex2f(a+x,b+y);
}
glEnd();
/*
glBegin(GL_TRIANGLE_FAN);
//glBegin(GL_LINE_STRIP);
glVertex2f(my_x, my_y); // origin
for (i = 0; i <= triangles; i++) {
glColor3f(0, 0.7, 0);
float x = radius * cos(i * twoPi / triangles);
float y = radius * sin(i * twoPi / triangles);
glVertex2f( x+0.2, y+0.2);
//glColor3f(0, 0, (i*20));
}
glEnd();
*/
}
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_ANY_PROFILE);
GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr);
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
Initialize();
float delta = glfwGetTime();
RenderCircle();
//RenderScene(window);
// Swap the screen buffers
glfwSwapBuffers(window);
// Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions
glfwPollEvents();
}
// Terminate GLFW, clearing any resources allocated by GLFW.
glfwTerminate();
return EXIT_SUCCESS;
}
static void Initialize(void) {
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
}