Sign in to follow this  
Syrinth

OpenGL Issues setting up/starting with OpenGL and possibly missing files?

Recommended Posts

Hello, I did a brief check and I'm sure I missed a similar topic somewhere but I think my issues may be a touch more specific.

A friend convinced me that I should be using OpenGL over DirectX and I can understand his reasoning which brought me to the NeHe site. I am trying to follow the tutorials but I get the following error:

Main.obj : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function "void __cdecl ReSizeGLScene(int,int)" (?ReSizeGLScene@@YAXHH@Z)

I have the following code segments in my project that I think are relevant:

[CODE]
#include <windows.h> // Header File For Windows
#include <gl/gl.h> // Header File For The OpenGL32 Library
#include <gl/glu.h>
#include <SDL_opengl.h>
----------------------------
GLvoid ReSizeGLScene(GLsizei width, GLsizei height){
if(height == 0)
height =1;

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
[/CODE]

It should be noted that I don't seem to have an opengl library file on my computer. I assume that's a problem but I'm not entirely certain where I should be downloading a new one from.

I am using glew and SDL as per my friend's advice.

Any help on any of the above would be greatly appreciated as this has been a cause of massive stress for me. Additionally, any better tutorials than NeHe would be great since they seem to be several years old and I'm sure they're deprecated by now...

Share this post


Link to post
Share on other sites
You need to link with opengl32.lib and glu32.lib and also the SDL library. That depends on your IDE.

Or use the pragma "command"
http://www.opengl.org/wiki/FAQ#Unresolved_External_Symbol

Share this post


Link to post
Share on other sites
What compiler and build environment are you using? The only one I'm aware of that won't include these libs is Visual C++ 2005 Express (both 2008 and 2010 do). Otherwise you do have them.

you don't need to go looking through your filesystem for these. They're installed automatically and Visual C++ (and other environments) will be automatically set up with the correct paths to be able to find them. There's nothing you need to do aside from just link to them. The only way they could be missing is if you've done something yourself to remove them.

What happens if you put this at the top of your program?
[code]#pragma comment (lib, "opengl32.lib")
#pragma comment (lib, "glu32.lib")[/code]

Share this post


Link to post
Share on other sites
One additon for others who might read this: If you're using an IDE that doesn't install the OpenGL libraries you can download and install the Windows SDK from microsoft.com to get the missing libraries (and the latest version of other system libraries)

Share this post


Link to post
Share on other sites
Having another issue that I'm hoping you all can help with.

I am trying to follow the tutorials here [url="http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/"]http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/[/url] since NeHe is very old. I saw this recommended in another post and thought I'd give it a try.

However. I can't get it to 'work'. It compiles and runs but the window fails and I'm reasonably certain that it outputs all of the failure cases below (the window vanishes way too fast for me to tell and print screen is not working when I try to capture it.)

[CODE]
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glfw.h>
#include <glm/glm.hpp>
using namespace glm;
int main( void )
{
// Initialise GLFW
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
return -1;
}
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE,GL_TRUE);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Open a window and create its OpenGL context
if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
{
fprintf( stderr, "Failed to open GLFW window\n" );
glfwTerminate();
return -1;
}
// Initialize GLEW
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
glfwSetWindowTitle( "Playground" );
// Ensure we can capture the escape key being pressed below
glfwEnable( GLFW_STICKY_KEYS );
// Dark blue background
glClearColor(0.0f, 0.0f, 0.3f, 0.0f);
do{
// Draw nothing, see you in tutorial 2 !
// Swap buffers
glfwSwapBuffers();
} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
glfwGetWindowParam( GLFW_OPENED ) );
// Close OpenGL window and terminate GLFW
glfwTerminate();
return 0;
}
[/CODE]

I'm obviously doing something wrong but I just can't imagine what!

Share this post


Link to post
Share on other sites
In that case, use your debugger to step through the code.
Or, output line by line to a text file so that you'll know where the code is stopping and what the error code is.

Share this post


Link to post
Share on other sites
*sigh* This has just been one huge, demoralizing headache.

Ok, so in order to start testing this code, I needed to separate it from the huge project it was a part of because it had an issue of it being all bundled together and you were apparently just supposed to run the exe outside of VC 2010...

So I copied and pasted the above code into a new project and then realized I didn't have either glfw or glm (not part of the original problem as they came packaged with those tutorials.) So I downloaded the appropriate uh, I'm not sure what to call them... extensions? and included them in my project.

Now I am getting all of this!


1>SDLmain.lib(SDL_win32_main.obj) : error LNK2005: _main already defined in Main.obj
1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Main.obj : error LNK2019: unresolved external symbol _glfwGetWindowParam referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _glfwGetKey referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _glfwSwapBuffers referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _glfwEnable referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _glfwSetWindowTitle referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol __imp__glewInit referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _glfwTerminate referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _glfwOpenWindow referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _glfwOpenWindowHint referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function _main
1>SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol _SDL_main referenced in function _main

So I assume that there's something wrong with my SDL?

I have the following includes and libraries:

F:\Programming\glew-1.7.0\include
F:\Programming\glfw-2.7.3\include
F:\Programming\SDL-1.2.15\include
F:\Programming\glm - 0931

F:\Programming\glew-1.7.0\lib
F:\Programming\glfw-2.7.3\lib
F:\Programming\SDL-1.2.15\lib\x86

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