Sign in to follow this  
Followers 0
Ubermeowmix

OpenGL
Help with OpenGL initialization

3 posts in this topic

Right I've been trying to start a simple window for ages now, it just gives:

1>LINK : fatal error LNK1104: cannot open file 'freeglut.lib'

Whatever I try.

 

Copied the files to VC/include/GL directories, included the path in additional dependancies in Linker->general->additional includes but nothing.

 

I keep reading about 'Making' the file when I download freeGLUT but when I open the VS file in C:\freeglut-2.8.1\VisualStudio\2010 and try to build it I get the same error (unable to open freeglut.lib).

 

I even tried the following I read on a forum:

 

#define FREEGLUT_STATIC
#define    _LIB
#define FREEGLUT_LIB_PRAGMAS=0
//You need that FREEGLUT_STATIC to let GLUT know that it's linking statically. Otherwise it looks for a DLL.

 

that just thows the following error

\sample.cpp(30): error C2008: '=' : unexpected in macro definition
\sample.cpp(30): warning C4005: 'FREEGLUT_LIB_PRAGMAS' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\freeglut_std.h(51) : see previous definition of 'FREEGLUT_LIB_PRAGMAS'

 

What am I doing wrong guys I'm getting really fed up of this, please can someone help?

 

The code i'm using is as follows:

 

#include <stdio.h>
#include <stdlib.h>

#if defined(__APPLE__)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif



#define NENDS 2           /* number of end "points" to draw */

GLdouble width, height;   /* window width and height */
int wd;                   /* GLUT window handle */
int ends[NENDS][2];       /* array of 2D points */

/* Program initialization NOT OpenGL/GLUT dependent,
   as we haven't created a GLUT window yet */
void
init(void)
{
  width  = 1280.0;                 /* initial window width and height, */
  height = 800.0;                  /* within which we draw. */
  ends[0][0] = (int)(0.25*width);  /* (0,0) is the lower left corner */
  ends[0][1] = (int)(0.75*height);
  ends[1][0] = (int)(0.75*width);
  ends[1][1] = (int)(0.25*height);
}

/* Callback functions for GLUT */

/* Draw the window - this is where all the GL actions are */
void
display(void)
{
  int i;

  /* clear the screen to white */
  glClearColor(1.0, 1.0, 1.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT);

  /* draw a black line */
  glColor3f(0.0, 0.0, 0.0);
  glBegin(GL_LINES);
    for (i = 0; i < NENDS; ++i) {
      glVertex2iv((GLint *) ends[i]);
    }
  glEnd();
  glFlush();
}

/* Called when window is resized,
   also when window is first created,
   before the first call to display(). */
void
reshape(int w, int h)
{
  /* save new screen dimensions */
  width = (GLdouble) w;
  height = (GLdouble) h;

  /* tell OpenGL to use the whole window for drawing */
  glViewport(0, 0, (GLsizei) width, (GLsizei) height);

  /* do an orthographic parallel projection with the coordinate
     system set to first quadrant, limited by screen/window size */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0.0, width, 0.0, height);
}

int
main(int argc, char *argv[])
{
  /* perform initialization NOT OpenGL/GLUT dependent,
     as we haven't created a GLUT window yet */
  init();

  /* initialize GLUT, let it extract command-line
     GLUT options that you may provide
     - NOTE THE '&' BEFORE argc */
  glutInit(&argc, argv);

  /* specify the display to be single
     buffered and color as RGBA values */
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);

  /* set the initial window size */
  glutInitWindowSize((int) width, (int) height);

  /* create the window and store the handle to it */
  wd = glutCreateWindow("Experiment with line drawing" /* title */ );

  /* --- register callbacks with GLUT --- */

  /* register function to handle window resizes */
  glutReshapeFunc(reshape);

  /* register function that draws in the window */
  glutDisplayFunc(display);

  /* start the GLUT main loop */
  glutMainLoop();

  return 0;
}

0

Share this post


Link to post
Share on other sites

Right I've been trying to start a simple window for ages now, it just gives:
1>LINK : fatal error LNK1104: cannot open file 'freeglut.lib'
Whatever I try.

Copied the files to VC/include/GL directories, included the path in additional dependancies in Linker->general->additional includes but nothing.


There's no problem with your includes if you get that error, everything is compiled fine but you're missing the .lib file. Are you sure that the lib file is in some of the directories where VC searches for them?

Edit: Also, make sure that if you're compiling 64-bit stuff, the lib file needs to be 64-bit too, same goes for 32-bit. Edited by Sponji
0

Share this post


Link to post
Share on other sites
I don't know why the complier won't accept the freeglut library file but I don't think you need it since you are loading 'glut.h' I suspect that you should be using glut32.lib, and you should have a copy of glut32.dll.

Just make sure that you have a matching set since different versions of these files likely won't work. If you want to message me your email address I'll send them to you.
0

Share this post


Link to post
Share on other sites

Fixed it, schoolboy error!

 

I was including the whole freeGlut folder under Linker->general->additional includes

 

That is sooooo totally wrong, you have to (step by step)

 

1. Download & copy the freeGlut folder to your project.

2. Link in VC++Directories

2a. In 'Include Directories' the include folder in your copied freeGlut folder

2b. In 'Library Directories', to the lib folder respectively.

3. Add OpenGL32.lib, freeglut.lib to the Linker->Input->Additional Dependencies section.

 

Run the code and have a great weight lifted from your shoulders!

3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0