1
votes

I am opengl beginner. I set the DLLs, Library, Header but, error occurred. My development environment is win7 ( 64bit ).

For reference - DLLs : C:\Windows\System32, C:\Windows\SysWOW64 // glu32.dll, glut.dll, glut32.dll, opengl32.dll

Libs : C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib, C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib // glut.lib, glut32.lib

Header : C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\gl, C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\gl // GL.H, GLAUX.H, GLU.H, glut.h

#include <Windows.h>
#include <gl/glut.H>

void DoDisplay ( void )
{
    glClearColor ( 0.0f, 0.0f, 1.0f, 1.0f );
    glClear( GL_COLOR_BUFFER_BIT );

    glBegin ( GL_TRIANGLES );

    glVertex2f ( 0.0, 0.5 );
    glVertex2f ( -0.5, -0.5 );
    glVertex2f ( 0.5, -0.5 );

    glEnd ();
    glFlush ();
}

int main ( int argc, char ** argv )
{
    glutInit ( &argc, argv );
    glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE );
    glutInitWindowSize ( 300, 300 );
    glutInitWindowPosition ( 0, 0 );
    glutCreateWindow ( "OpenGL" );
    glutDisplayFunc ( DoDisplay );
    glutMainLoop ();

    return 0;
}

Edit :

White Window : http://i.stack.imgur.com/9GJoN.jpg

This code is simply output the white triangle.

Win32 Project -> Console Project.

Problem not solved.. sorry.

Error is http://i.stack.imgur.com/9GJoN.jpg

2
no glutInit(), missing glBegin() and some other problems, you're going to have to be more specific with what the problem is and what you are actually trying to do. - PeterT

2 Answers

3
votes
  • You're using immediate mode. You have a glEnd() but no glBegin()
  • As PeterT also pointed out, you have no call to glutInit
  • If your paths are specified like the way you have printed, you'll run into a problem. You have both forward and backslashes, which at least in my experience ruins the path.
  • You're not clearing the screen to a specific color, nor are you setting your vertices to a specific color. This may be the case of drawing a polar bear in a snow storm.

Check out

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

and

glClearColor(r, g, b, a);
  • As Drew McGowen pointed out, you're not specifying any transformation or projection matrices.
  • I would strongly recommend looking for a tutorial on OpenGL to get a good explanation of all the things you need to do to draw a triangle and why. Lighthouse3d, Swiftless, OGLDev - there are many that should show you the basics.
  • One more point: You're trying to learn code that has been deprecated for ~7 years. You should learn the new programmable pipeline instead of the fixed function pipeline because it is faster and gives you more control.
1
votes
void DoDisplay ( void )
{
    ...
    glFlush ();
}

int main ( int argc, char ** argv )
{
    ...
    glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE );
    ....
}

glFlush() is insufficient when using GLUT_DOUBLE. Use glutSwapBuffers() instead.