0

i was trying to setup opengl libraries on visual studio 2013 this code for drawing a triangle i don't have error in error list which relate to include files but it dosen't work this is the code:

#include<glut.h>

static void redraw();

void main()
{
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(100, 100); 
    glutInitWindowSize(400, 300); 
    glutCreateWindow("Application11");
    glutDisplayFunc(redraw);
    glutMainLoop();
}

static void redraw()
{
    glBegin(GL_TRIANGLES);
    glVertex2f(0,1);
    glVertex2f(0.5,0);
    glVertex2f(0.5,0);
    glColor3f(1,0,0);
    glEnd();
    glFlush();
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 1) You are setting the color *after* the triangle has been drawn. 2) Your second and third vertex are the same. – BDL Oct 18 '17 at 20:35

1 Answers1

0

You have to initialize the GLUT library (see glutInit):

Either:

int main()
{
    int cnt = 0;
    glutInit(&cnt, NULL);
    .....

or

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    .....

Further 2 points of your triangle are equal. Change it for example to:

 glBegin(GL_TRIANGLES);
 glColor3f(1.0f, 0.0f, 0.0f);
 glVertex2f( 0.0f, 1.0f );
 glVertex2f( 0.5f, 0.0f );
 glVertex2f( 0.5f, 1.0f );
 glEnd();


See further Undefined reference when using glew and mingw?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174