Hello,
I am trying to display 10 different sized triangles on screen and at the moment nothing appears when I run the code.
Some help would be great
#include<ctime>
#include<cstdlib>
#include<GL/glut.h>
#include<cmath>
using namespace std;
void start_random()
{
static bool seeded = false;
if (!seeded){
srand((unsigned)time(NULL));
seeded = true;
}
}
// Generate a random float in the range -1 to +1…
float rnd(){
start_random();
return (-1) + (float)rand() / 16384;
}
class Triangle
{
public:
Triangle(float X, float Y, float width, float height);
void Show();
private:
float x, y, w, h;
};
Triangle::Triangle(float X, float Y, float width, float height)
{
x = rnd(); y = rnd(); w = rnd(); h = rnd();
}
void Triangle::Show()
{
glVertex2f(x, y);
glVertex2f(x - 0.5w, y - h);
glVertex2f(x + 0.5w, y - h);
}
void CreateShapes(float x, float y, float w, float h)
{
for (int i = 0; i < 100; i++)
{
Triangle t(x, y, w, h);
t.Show();
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1, 0, 0);
void CreateShapes(float x,float y,float w,float h);
glFlush();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutCreateWindow("Random Shapes");
glClearColor(1, 1, 1, 1);
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}