Can anyone explain what's going on or not going on so that I can correct it. Here's the code so far from a .cpp file. Running in Visual Studio Community 2015.
#include <windows.h>
#include <gl/GL.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <math.h>
#define M_PI 3.14159265358979323846
const int screenWidth = 640;
const int screenHeight = 480;
Here aa
, bb
, cc
, & dd
are used to map the world coordinates to screen coordinates. I printed them out to make sure it was working correctly and the coordinates are being calculated correctly. In this case 0 < radius <= 5.
void drawHex(GLdouble radius, GLdouble aa, GLdouble bb, GLdouble cc, GLdouble dd) {
glBegin(GL_POLYGON);
for (int i = 0; i < 6; i++) {
glVertex2d(((cos(i / 6.0 * 2 * M_PI) * radius) * aa) + cc,
((sin(i / 6.0 * 2 * M_PI) * radius) * bb) + dd);
}
glEnd();
glFlush();
}
Here I calculate A
, B
, C
, and D
to map the world to the view and pass them to the drawHex
function.
void myDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT);
GLdouble winWidth = glutGet(GLUT_WINDOW_WIDTH);
GLdouble winHeight = glutGet(GLUT_WINDOW_HEIGHT);
GLdouble A, B, C, D;
glViewport((GLint)0, (GLint)0, (GLint)winWidth, (GLint)winHeight);
A = winWidth / 10.0;
B = winHeight / 10.0;
C = 0 - (A * -5.0);
D = 0 - (B * -5.0);
drawHex(0.5, A, B, C, D);
}
Program inits and main loop.
void myInit() {
glClearColor(0.93, 0.93, 0.93, 0.0);
glColor3f(1.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-5.0, 5.0, -5.0, 5.0);
glClear(GL_COLOR_BUFFER_BIT);
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(100, 150);
glutCreateWindow("Window");
myInit();
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}
All I get is a blank window with the background color. I'm expecting a hexagon in the middle of the view (not yet resized to maintain a proper aspect ratio).