الأحد، 13 ديسمبر 2015

Draw circle



// Example_2_1.cpp : Defines the entry point for the console application.
//
// Author  : ALIA

// Simple circul OpenGL
//
// Last tested in Visual C++ 2010 Express

//#include "stdafx.h"
#include <gl/glut.h>
#include <math.h>



//======================================================
// DISPLAY CALL BACK ROUTINE
//======================================================
void DrawCircle(float cx, float cy, float r, int num_segments)
{
glBegin(GL_LINE_LOOP);
for(int ii = 0; ii < num_segments; ii++)
{
float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle

float x = r * cosf(theta);//calculate the x component
float y = r * sinf(theta);//calculate the y component

glVertex2f(x + cx, y + cy);//output vertex

}
glEnd();
}

void displayCallBack()
{
    // Clear the window
glClear(GL_COLOR_BUFFER_BIT);


DrawCircle(0,0,1,100);

// Flush the buffer to force drawing of all objects thus far
glFlush();
}

//======================================================
// MAIN PROGRAM
//======================================================
void main( int argc, char **argv)
{
// Create the Window
glutCreateWindow("Example ");
   
// Assign displayCallBack() to be the function called whenever a display
// event occurs, generally after a resize or expose event
glutDisplayFunc(displayCallBack);

// Print information about the application in the command console
//printf("OpenGL Console Output: Hello World\nNo Interaction with this application possible.");

//Enter infinite loop calling 'displayCallBack'
glutMainLoop();

// return 0;
}

ليست هناك تعليقات:

إرسال تعليق