SFML community forums
Help => Graphics => Topic started by: mopie on December 11, 2009, 05:07:43 pm
-
hello.
I'm discovering sfml lib and i would like to be able to use opengl.
I pasted the code of the tutorial (http://www.sfml-dev.org/tutorials/1.5/window-opengl-fr.php).
I was not compiling because of errors during the linkage.
Error 1 error LNK2001: unresolved external symbol __imp__glDeleteTextures@8 main.obj
Error 2 error LNK2001: unresolved external symbol __imp__glClearDepth@8 main.obj
Error 3 error LNK2001: unresolved external symbol __imp__glClear@4 main.obj
Error 4 error LNK2001: unresolved external symbol __imp__glTexCoord2f@8 main.obj
Error 5 error LNK2001: unresolved external symbol __imp__glEnd@0 main.obj
Error 6 error LNK2001: unresolved external symbol __imp__glBindTexture@8 main.obj
Error 7 error LNK2001: unresolved external symbol __imp__glBegin@4 main.obj
Error 8 error LNK2001: unresolved external symbol __imp__glDepthMask@4 main.obj
Error 9 error LNK2001: unresolved external symbol __imp__glColor4f@16 main.obj
Error 10 error LNK2001: unresolved external symbol __imp__glTexParameteri@12 main.obj
Error 11 error LNK2001: unresolved external symbol __imp__glRotatef@16 main.obj
Error 12 error LNK2001: unresolved external symbol __imp__glVertex3f@12 main.obj
Error 13 error LNK2001: unresolved external symbol __imp__glMatrixMode@4 main.obj
Error 14 error LNK2001: unresolved external symbol __imp__glViewport@16 main.obj
Error 15 error LNK2001: unresolved external symbol __imp__glTranslatef@12 main.obj
Error 16 error LNK2001: unresolved external symbol __imp__glEnable@4 main.obj
Error 17 error LNK2001: unresolved external symbol __imp__glGenTextures@8 main.obj
Error 18 error LNK2001: unresolved external symbol __imp__glLoadIdentity@0 main.obj
Error 19 fatal error LNK1120: 18 unresolved externals
So i downloaded the glut lib found there : http://www.xmission.com/~nate/glut.html
I was surprising to see that the lib was very old (2001... !!!).
Then, i added this include to the code.
which redirect to what i downloaded.
#include <gl/glut.h>
And, miracle, the compilation works.
Is all i did is right ? Did i did anything wrong ?
Because when i stop the application, it crash.
I breakpoint the executation, i saw the error was after the main return.
If anybody has any idea ?
Thanks
Ps. I'm working with Seven and VisualStudio 2008
-
Including GLUT headers should solve nothing, the errors are from the linker about the OpenGL library, and the solution to this is to link to opengl32.lib.
-
Oki. Thanks for your answer.
But where can i find this lib ?
The website of opengl is not very efficient to found something...
-
opengl.lib is distributed with your compiler, so you don't have to find it actually. Just add "opengl32.lib" to your linker settings and that's it.
-
ok. Thanks.
I added opengl32.lib.
Some problems were solved but there are always this one :
Error 1 error LNK2001: unresolved external symbol _gluPerspective@32 main.obj
Error 2 error LNK2001: unresolved external symbol _gluBuild2DMipmaps@28 main.obj
Do you have an idea ?
-
glu32.lib ;)
-
Now the compilation and linkage work. :)
But i have always the problem at the closing of the program.
Here is a picture to show you :
http://www.hiboox.fr/go/images/informatique/untitled2,b685e5c598814b0ae6ec6c34f2c9ef47.png.html
-
Sorry, I have no idea why it crashes :?
-
ok. Thanks. I'll do some tests :)
-
I did some tests and all is ok ;)
But i have now an other problem.
I have discovered the bind method into the sf::image class.
I use it to apply some textures to my scene.
But the problem is that when i use the bind method i got some stanges messages at the closing of the program:
An internal OpenGL call failed in image.cpp (481) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in image.cpp (482) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
My code is the following :
//Initalization//
sf::RenderWindow App(sf::VideoMode(WIDTH, HEIGHT), "SFML OpenGL");
App.PreserveOpenGLStates(true);
App.SetFramerateLimit(60);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,WIDTH,HEIGHT,0,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (!this->_texture->LoadFromFile("img\\2.bmp"))
//except
//render func
glClear (GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(this->getX(), this->getY(),0);
this->_texture->Bind();
glBegin(GL_QUADS);
glTexCoord2i(0,0); glVertex2f(0,0);
glTexCoord2i(1,0); glVertex2f(0,50);
glTexCoord2i(1,1); glVertex2f(50,50);
glTexCoord2i(0,1); glVertex2f(50, 0);
glEnd();
App.Display();
Thanks ;)
-
up plz ;)
-
Can you provide a complete source code?
-
Yeah. here is a little messy test:
#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "sfml");
float x = 400;
float y = 300;
App.PreserveOpenGLStates(true);
App.SetFramerateLimit(60);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,800,600,0,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
sf::Image texture;
if (!texture.LoadFromFile("data\\text.jpg"))
return 0;
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
glClear (GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(x, y,0);
texture.Bind();
glBegin(GL_QUADS);
glTexCoord2i(0,0); glVertex2f(0,0);
glTexCoord2i(1,0); glVertex2f(0,50);
glTexCoord2i(1,1); glVertex2f(50,50);
glTexCoord2i(0,1); glVertex2f(50, 0);
glEnd();
App.Display();
App.Display();
}
return EXIT_SUCCESS;
}
The code seems to work properly. But at the closing of the program i got the following message :
An internal OpenGL call failed in image.cpp (481) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in image.cpp (482) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
-
What about the samples of the SDK?