I am trying to make a lunar lander type game to start off opengl with, but i cant get get the object to show, if anyone could help out to why this isnt showing, it would be greatly appreciated . This is the code i have
main
#include <iostream>
#include <GL/glut.h>
#include "Lander.h"
#include "random.h"
using namespace std;
float startx = rnd(100, 600); float starty = rnd(350, 450); int startradius = 10;
Lander lander(startx, starty, startradius);
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
lander.show();
glutSwapBuffers();
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(1000, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("Animation Example");
glClearColor(1.0, 1.0, 1.0, 0.0);
glutDisplayFunc(display);
glutMainLoop();
}
Lander.h
#ifndef Lander_H
#define Lander_H
class Lander
{
public:
Lander(float ix, float iy, int iradius);
void show();
void draw();
private:
float x, y, radius;
};
#endif
Lander.cpp
#include "Lander.h"
#include<gl/glut.h>
#include <cmath>
Lander::Lander(float ix, float iy, int iradius)
{
x = ix; y = iy; radius = iradius;
}
void Lander::show()
{
glPushMatrix();
glTranslatef(x, y, 0);
glRotatef(22, 0, 0, 1);
glTranslatef(-x, -y, 0);
draw();
glPopMatrix();
}
void Lander::draw()
{
glBegin(GL_POLYGON);
const int NPOINTS = 8;
const float TWOPI = 2 * 3.1415927;
const float STEP = TWOPI / NPOINTS;
glColor3f(1.0, 0.0, 0.0);
for (float angle = 0; angle<TWOPI; angle += STEP)
glVertex2f(x + radius*cos(angle), y + radius*sin(angle));
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(x - 6, y - 6);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(x - 12, y - 12);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(x, y - 8);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(x, y - 17);
glEnd();
}