I’m trying to draw an ellipse and tried google and I have failed to make any useful progress. Here Are the codes I took on the internet and did a lot of modification, adding and removing to suit my needs and it does not work.
Please help me point what is wrong
Thanks
main.h
#include <GL/glut.h>
#include <cmath>
using namespace std;
//initiate display
void glutIniStuffs(int argc, char** argv) ;
//Create the window
int glutCreateWindow(char *title);
//Render our scene
void drawScene();
void changeSize(int w, int h);
//Register all call backs here
void registerCallBacks();
void drawEllipse(float radiusX, float radiusY);
main.cpp
#include "main.h"
void glutIniStuffs(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(500, 500); // window size
glutInitWindowPosition((glutGet(GLUT_SCREEN_WIDTH)-640)/2, (glutGet(GLUT_SCREEN_HEIGHT)-480)/2); // window location
}
#define DEG2RAD 3.14159/180.0
void drawEllipse(float radiusX, float radiusY) {
int i;
glBegin(GL_LINE_LOOP);
for(i=0; i<360; i++) {
float rad = i*DEG2RAD;
glVertex2f(cos(rad)*radiusX,
sin(rad)*radiusY);
}
glEnd();
}
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.9f, 0.0f, 0.9f);
GLfloat axisZ = -15;
//glTranslated(-1.25, -1, 1);
drawEllipse(2.0, 2.8);
glutSwapBuffers();
}
void registerCallBacks() {
// register callbacks
//Draw function
glutDisplayFunc(drawScene);
//redraw function
glutReshapeFunc(changeSize);
}
void changeSize(int w, int h) {
// Prevent a divide by zero, when window is too short -- (you cant make a window of zero width).
if(h == 0) {
h = 1;
}
float winRatio = 1.0* w / h;
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION);
// Reset Matrix
glLoadIdentity();
// Set the correct perspective.
// Set the Field of view angle (in degrees), the aspect ratio of our window, and the new and far planes
gluPerspective(60, winRatio, 1.0, 100.0);
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv) {
//initalize glut
glutIniStuffs(argc, argv);
//create window
glutCreateWindow("House Made with OpenGL");
//register callbacks
registerCallBacks();
glutMainLoop();
return 0;
}