I can't get the output of what code, or at least as far as I can tell what should be the output, to show up on my screen. Would anyone be able to help me?
//Draw function using world coordinates and viewport
#include <math.h>
#include <GL/glut.h>
#define PI 3.14159265359
const int screenWidth = 640;
const int screenHeight = 480;
const int aspectRatio = 2;
// setWindow
void setWindow(float left, float right, float bottom, float top)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(left, right, bottom, top);
}
// setViewport
void setViewport(int left, int right, int bottom, int top)
{
glViewport(left, bottom, right - left, top - bottom);
}
// myInit
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(1.0f, 0.0f, 0.0f);
glPointSize(1.0);
}
void myReshape(GLsizei W, GLsizei H)
{
if (aspectRatio > W/H)
setViewport(0, W, 0, W/aspectRatio);
else
setViewport(0, H*aspectRatio, 0, H);
}
// myDisplay
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
setWindow(0.0, (2 * PI), -1.0, 1.0);
setViewport(0, 80, 0, 40);
glBegin(GL_LINE_STRIP);
GLdouble x, y, a;
for (a = 0; a < (2 * PI); a += 0.0005)
x = (10 + sin(15 * a));
y = sin(a);
glVertex2d(x,y);
glEnd();
glFlush();
}
// main
int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(100, 150);
glutCreateWindow("Dot plot a function using world window and viewport.");
myInit();
glutReshapeFunc(myReshape);
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}
I'm trying to do something out of a book I got, it says the formula I shoud use is: "the x coordinate is driven by the parameter a and is given by x(a) = 10 + sin(15 * a) as a varies from 0 to 2PI. The y cordinate is given by y(a) = sin(a), and varies over the same range."
Its supposed to make a squiggly circle but it just comes up with a blank window. Any help would much appreciated.
EDIT: I suppose I should give some info about what I'm using. I'm using the latest version of freeglut, and the latest code::blocks ide. I know its old code(like opengl 1 or something from what my friends have said when they looked at the code). Its for a class, otherwise I'd be learning at least opengl 3.0 instead of this.