0

I'm trying to compile this simple dot program with C++ that uses OpenGL. I made a struct GLintPoint to hold just points x and y.
It seems I didn't delcare the struct according to the errors.

#include <GL/glut.h>
#include <stdlib.h>
#include <time.h>

struct GLPoint
{
  GLint x;
  GLint y;
};

void myInit(void)
{
  glClearColor(1.0, 1.0, 1.0, 0.0);
  glColor3f(0.0, 0.0, 1.0);
  glPointSize(4.0);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}

void drawDot(int x, int y)
{
  glBegin(GL_POINTS);
    glVertex2i(x, y);
  glEnd();
}


void gasket(void)
{
  glClear(GL_COLOR_BUFFER_BIT);
  GLPoint T[3] = {{20, 20}, {620, 20}, {300, 460}};
  int index = rand() % 3;
  GLPoint point T[index];
  drawDot(point.x, point.y);
  for (int i = 0; i < 55000; i++)
   {
     index = rand() % 3;
     point.x =  (point.x + T[index]) / 2;
     point.y = (point.y + T[index]) / 2;
     drawDot(point.x, point.y);
   }

}


int main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(640, 480);
  glutInitWindowPosition(200, 200);
  glutCreateWindow("Dot");
  glutDisplayFunc(gasket);
  myInit();
  glutMainLoop();
}

Edited by tyricec: didn't know how to put in code

Attachments
#include <GL/glut.h>
#include <stdlib.h>
#include <time.h>

struct GLPoint
{
  GLint x;
  GLint y;
};

void myInit(void)
{
  glClearColor(1.0, 1.0, 1.0, 0.0);
  glColor3f(0.0, 0.0, 1.0);
  glPointSize(4.0);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}

void drawDot(int x, int y)
{
  glBegin(GL_POINTS);
    glVertex2i(x, y);
  glEnd();
}


void gasket(void)
{
  glClear(GL_COLOR_BUFFER_BIT);
  GLPoint T[3] = {{20, 20}, {620, 20}, {300, 460}};
  int index = rand() % 3;
  GLPoint point T[index];
  drawDot(point.x, point.y);
  for (int i = 0; i < 55000; i++)
   {
     index = rand() % 3;
     point.x =  (point.x + T[index]) / 2;
     point.y = (point.y + T[index]) / 2;
     drawDot(point.x, point.y);
   }

}


int main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(640, 480);
  glutInitWindowPosition(200, 200);
  glutCreateWindow("Swag");
  glutDisplayFunc(gasket);
  myInit();
  glutMainLoop();
}
2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by tyricec
1

The issue lies within your function gasket().

On line 34 you are missing an equals sign between point and T, so it should look like

GLPoint point = T[index];

Then when you are adding point.x and t[index] then dividing by 2 you really want to add each component then divide by two. So line 42 and 43 should look like

point.x = (point.x + T[index].x) / 2;
point.y = (point.y + T[index].y) / 2;

Also I'm not sure about you but when I try to compile it gives me a bunch of undefined reference errors about all the OpenGL functions, so at the top I had to put

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
0

Wow thanks, I did forget an equal sign. All this time I thought I had an error at line 32 so that's why I didn't even look there.
I'm using my school's computer so I believe we have our libraries referenced in the Makefile which makes it where I only need the glut.h to be called when I need it.
Once again, thanks.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.