Jump to content
  • Advertisement
Sign in to follow this  
kcabsinosam

OpenGL Beginning OpenGL Linking Error

This topic is 5092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include <gl\glut.h>
#include <stdlib.h>

void Initialize();
void MouseHandler(int button, int state, int x, int y);
void KeyboardHandler(unsigned char key, int x, int y);
void MainMenuHandler(int option);
void Animate();
void Reshape(int width, int height);
void Display();


/****************************************************************************
 main()

 Setup GLUT and OpenGL, drop into the event loop
*****************************************************************************/
int main(int argc, char **argv)
{
  // Setup the basic GLUT stuff
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

  // Create the window
  glutInitWindowSize(1024, 768);
  glutInitWindowPosition(100, 150);
  glutCreateWindow("BOGLGP Chapter 1");

  Initialize();

  // Register the event callback functions
  glutDisplayFunc(Display); 
  glutReshapeFunc(Reshape);
  glutMouseFunc(MouseHandler);
  glutKeyboardFunc(KeyboardHandler);
  glutIdleFunc(Animate);

  // At this point, control is relinquished to the GLUT event handler.
  // Control is returned as events occur, via the callback functions.
  glutMainLoop();   
   
  return 0;
} // end main()


/****************************************************************************
 Initialize()

 One time setup, including creating menus, creating a light, setting the
 shading mode and clear color, and loading textures.
*****************************************************************************/
void Initialize()
{
  // set up the only meny
  int mainMenu;

  mainMenu = glutCreateMenu(MainMenuHandler);

  glutSetMenu(mainMenu);
  glutAddMenuEntry("Exit", 0);
  glutAttachMenu(GLUT_RIGHT_BUTTON);

  glEnable(GL_DEPTH_TEST);
} // end Initialize()


/****************************************************************************
 MouseHandler()
 
 Handle mouse events. For this simple demo, just exit on a left click.
*****************************************************************************/
void MouseHandler(int button, int state, int x, int y)
{
  switch (button)
  {
  case GLUT_LEFT_BUTTON:
    {
      exit(0);
    } break;
  default:
    break;
  }

  // force a screen redraw
  glutPostRedisplay();
} // end MouseHandler()


/****************************************************************************
 KeyboardHandler()

 Keyboard handler. Again, we'll just exit when q is pressed.
*****************************************************************************/
void KeyboardHandler(unsigned char key, int x, int y)
{
  switch (key)
  {
  case 'q':  // exit
    {
      exit(0);
    } break;
  default:
    {
    } break;
  }
  glutPostRedisplay();
} // end KeyboardHandler()


/****************************************************************************
 MainMenuHandler()

 Main menu callback.
*****************************************************************************/
void MainMenuHandler(int option)
{
  switch(option)
  {
  case 0:
    {
      exit(0);
    } break;
  default:
    break;
  }
  glutPostRedisplay();
} // end MainMenuHandler()


/****************************************************************************
 Animate()

 Rotate the cube by 4 degrees and force a redisplay.
*****************************************************************************/
void Animate()
{
  glutPostRedisplay();
} // end Animate()


/****************************************************************************
 Reshape()

 Reset the viewport for window changes
*****************************************************************************/
void Reshape(int width, int height)
{
  if (height == 0)
    return;

  glViewport(0, 0, (GLsizei) width, (GLsizei) height);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(90.0, width/height, 1.0, 100.0);

  glMatrixMode(GL_MODELVIEW);
} // end Reshape


/****************************************************************************
 Display()

 Clear and redraw the scene.
*****************************************************************************/
void Display()
{
  // set up the camera
  glLoadIdentity();
  gluLookAt(0.0, 1.0, 6.0,
            0.0, 0.0, 0.0,
            0.0, 1.0, 0.0);

  // clear the screen
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // draw a triangle
  glBegin(GL_TRIANGLES);
    glColor3f(1.0, 0.0, 0.0);
    glVertex3f(2.0, 2.5, -1.0);
    glColor3f(0.0, 1.0, 0.0);
    glVertex3f(-3.5, -2.5, -1.0);
    glColor3f(0.0, 0.0, 1.0);
    glVertex3f(2.0, -4.0, 0.0);
  glEnd();

  // draw a polygon
  glBegin(GL_POLYGON);
    glColor3f(1.0, 1.0, 1.0);
    glVertex3f(-1.0, 2.0, 0.0);
    glColor3f(1.0, 1.0, 0.0);
    glVertex3f(-3.0, -0.5, 0.0);
    glColor3f(0.0, 1.0, 1.0);
    glVertex3f(-1.5, -3.0, 0.0);
    glColor3f(0.0, 0.0, 0.0);
    glVertex3f(1.0, -2.0, 0.0);
    glColor3f(1.0, 0.0, 1.0);
    glVertex3f(1.0, 1.0, 0.0);
  glEnd();

  // draw everything and swap the display buffer
  glutSwapBuffers();
} // end Display()

Here is the linking errors.
Deleting intermediate files and output files for project 'simplemodified - Win32 Debug'.
--------------------Configuration: simplemodified - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/simplemodified.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

simplemodified.exe - 2 error(s), 0 warning(s)

I need to know which file I am missing and where to put it. I suppose in the Lib files in the Visual Studio Folder, but I am not positive. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Thank you mike...one more question if you do not mind though. Whenever I use glut when I am writing OpenGL applications, do I have to include glut32.dll in the same folder as the program?
This is asked because when I try and run the program it says "Cannot find glut32.dll. Please try re-installing the program."

Share this post


Link to post
Share on other sites
Quote:
Original post by mike25025
yes
or put it in c:/windows/

Ahh, I put it in C:/windows32
Thanks for the help, I must say you have helped me a lot so far!

Share this post


Link to post
Share on other sites
putting the glut dll into the same folder as the exe (or the project folder if running from inside something like Visual Studio) also works and if you plan to distro stuff is how you should do it, instead of putting the dll into the system directories [smile]

Share this post


Link to post
Share on other sites
Ok...I have done everything and it compiles, but when I try to run the .exe it gives me an error "This program is not responding...blah blah blah...if this problem persists please contact Microsoft". Should I make the program console instead of Win32?

Share this post


Link to post
Share on other sites
Here is my current source code. If there is anything wrong with it please tell me. I am trying to figure out why it will not run, but it compiles. I am linking glu32.lib and opengl32.lib if you are wondering.

#include <gl\glut.h>
#include <stdlib.h>

void Initialize();
void MouseHandler(int button, int state, int x, int y);
void KeyboardHandler(unsigned char key, int x, int y);
void MainMenuHandler(int option);
void Animate();
void Reshape(int width, int height);
void Display();


/****************************************************************************
main()

Setup GLUT and OpenGL, drop into the event loop
*****************************************************************************/

int main(int argc, char **argv)
{
// Setup the basic GLUT stuff
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

// Create the window
glutInitWindowSize(1024, 768);
glutInitWindowPosition(100, 150);
glutCreateWindow("BOGLGP Chapter 1");

Initialize();

// Register the event callback functions
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutMouseFunc(MouseHandler);
glutKeyboardFunc(KeyboardHandler);
glutIdleFunc(Animate);

// At this point, control is relinquished to the GLUT event handler.
// Control is returned as events occur, via the callback functions.
glutMainLoop();

return 0;
} // end main()


/****************************************************************************
Initialize()

One time setup, including creating menus, creating a light, setting the
shading mode and clear color, and loading textures.
*****************************************************************************/

void Initialize()
{
// set up the only meny
int mainMenu;

mainMenu = glutCreateMenu(MainMenuHandler);

glutSetMenu(mainMenu);
glutAddMenuEntry("Exit", 0);
glutAttachMenu(GLUT_RIGHT_BUTTON);

glEnable(GL_DEPTH_TEST);
} // end Initialize()


/****************************************************************************
MouseHandler()

Handle mouse events. For this simple demo, just exit on a left click.
*****************************************************************************/

void MouseHandler(int button, int state, int x, int y)
{
switch (button)
{
case GLUT_LEFT_BUTTON:
{
exit(0);
} break;
default:
break;
}

// force a screen redraw
glutPostRedisplay();
} // end MouseHandler()


/****************************************************************************
KeyboardHandler()

Keyboard handler. Again, we'll just exit when q is pressed.
*****************************************************************************/

void KeyboardHandler(unsigned char key, int x, int y)
{
switch (key)
{
case 'q': // exit
{
exit(0);
} break;
default:
{
} break;
}
glutPostRedisplay();
} // end KeyboardHandler()


/****************************************************************************
MainMenuHandler()

Main menu callback.
*****************************************************************************/

void MainMenuHandler(int option)
{
switch(option)
{
case 0:
{
exit(0);
} break;
default:
break;
}
glutPostRedisplay();
} // end MainMenuHandler()


/****************************************************************************
Animate()

Rotate the cube by 4 degrees and force a redisplay.
*****************************************************************************/

void Animate()
{
glutPostRedisplay();
} // end Animate()


/****************************************************************************
Reshape()

Reset the viewport for window changes
*****************************************************************************/

void Reshape(int width, int height)
{
if (height == 0)
return;

glViewport(0, 0, (GLsizei) width, (GLsizei) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0, width/height, 1.0, 100.0);

glMatrixMode(GL_MODELVIEW);
} // end Reshape


/****************************************************************************
Display()

Clear and redraw the scene.
*****************************************************************************/

void Display()
{
// set up the camera
glLoadIdentity();
gluLookAt(0.0, 1.0, 6.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);

// clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// draw a triangle
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(2.0, 2.5, -1.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-3.5, -2.5, -1.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(2.0, -4.0, 0.0);
glEnd();

// draw a polygon
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(-1.0, 2.0, 0.0);
glColor3f(1.0, 1.0, 0.0);
glVertex3f(-3.0, -0.5, 0.0);
glColor3f(0.0, 1.0, 1.0);
glVertex3f(-1.5, -3.0, 0.0);
glColor3f(0.0, 0.0, 0.0);
glVertex3f(1.0, -2.0, 0.0);
glColor3f(1.0, 0.0, 1.0);
glVertex3f(1.0, 1.0, 0.0);
glEnd();

// draw everything and swap the display buffer
glutSwapBuffers();
} // end Display()
int __stdcall WinMain(void*,void*,char*,int)
{
return main(0,0);
}



It is not my computer either, because I can run the excact same program, off the program on the CD. Can you tell me what is wrong, or should I make it console???

Share this post


Link to post
Share on other sites
Ok...after experimenting I got it to work when I make it a console project. Thanks for all your great help, it is really appreciated. You will probably be seeing more of me in this section as I am learning OpenGL after reviewing many aspects of it, I found it more understandable than Direct3D. Again, thanks for all your replies, they are greatly appreciated.

~MD

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!