Hi all,
I’m trying to write a code to draw a circle. I’m a beginner to openGL. Often when I write a code to do draw something like this I’m not getting anything on the scree. I generally have problem with glMarixmode(), glIdentity(), glviewport() and simialr functions like this. This is the code that I wrote and I’m simply getting a window with black background.
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <ios>
#include <math.h>
#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
#define WINDOW_X 1000
#define WINDOW_Y 1000
void doInit()
{
glClearColor(0.0,0.0,0.0,0.0);
glClear (GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
void reshape (int w, int h) {
glViewport (0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode (GL_MODELVIEW);
}
void dodisplay(void)
{
const float DEG2RAD = 3.14159/180;
int radius = 2;
glClearColor(0.0,0.0,0.0,1.0);
glColor3f(0.2,0.2,0.75);
glMatrixMode (GL_MODELVIEW);
glBegin(GL_LINE_LOOP);
for (int i=0; i< 360; i++)
{
float degInRad = i*DEG2RAD;
glVertex2f(cos(degInRad)*radius,sin(degInRad)*radius);
}
glEnd();
glFlush();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(WINDOW_X,WINDOW_Y);
glutInitWindowPosition(0,0);
glutCreateWindow(“Project”);
doInit();
glutDisplayFunc(dodisplay);
glutReshapeFunc (reshape);
glutMainLoop();
return 0;
}
can you guys briefly explain me when should I use all these functions in code and which one to use?
Regards,
Arun