Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sfml and opengl  (Read 8159 times)

0 Members and 1 Guest are viewing this topic.

mopie

  • Newbie
  • *
  • Posts: 9
    • View Profile
sfml and opengl
« 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.

Code: [Select]

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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfml and opengl
« Reply #1 on: December 11, 2009, 05:12:15 pm »
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.
Laurent Gomila - SFML developer

mopie

  • Newbie
  • *
  • Posts: 9
    • View Profile
sfml and opengl
« Reply #2 on: December 11, 2009, 05:35:50 pm »
Oki. Thanks for your answer.

But where can i find this lib ?

The website of opengl is not very efficient to found something...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfml and opengl
« Reply #3 on: December 11, 2009, 05:37:36 pm »
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.
Laurent Gomila - SFML developer

mopie

  • Newbie
  • *
  • Posts: 9
    • View Profile
sfml and opengl
« Reply #4 on: December 11, 2009, 05:54:13 pm »
ok. Thanks.

I added opengl32.lib.
Some problems were solved but there are always this one :
Code: [Select]
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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfml and opengl
« Reply #5 on: December 11, 2009, 05:56:49 pm »
glu32.lib ;)
Laurent Gomila - SFML developer

mopie

  • Newbie
  • *
  • Posts: 9
    • View Profile
sfml and opengl
« Reply #6 on: December 11, 2009, 06:05:54 pm »
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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfml and opengl
« Reply #7 on: December 11, 2009, 06:26:47 pm »
Sorry, I have no idea why it crashes :?
Laurent Gomila - SFML developer

mopie

  • Newbie
  • *
  • Posts: 9
    • View Profile
sfml and opengl
« Reply #8 on: December 11, 2009, 06:45:27 pm »
ok. Thanks. I'll do some tests :)

mopie

  • Newbie
  • *
  • Posts: 9
    • View Profile
sfml and opengl
« Reply #9 on: December 13, 2009, 01:34:16 am »
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:

Code: [Select]
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 :

Code: [Select]


//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 ;)

mopie

  • Newbie
  • *
  • Posts: 9
    • View Profile
sfml and opengl
« Reply #10 on: December 14, 2009, 03:11:31 pm »
up plz ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfml and opengl
« Reply #11 on: December 14, 2009, 03:17:03 pm »
Can you provide a complete source code?
Laurent Gomila - SFML developer

mopie

  • Newbie
  • *
  • Posts: 9
    • View Profile
sfml and opengl
« Reply #12 on: December 14, 2009, 03:51:09 pm »
Yeah. here is a little messy test:

Code: [Select]

#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 :

Code: [Select]
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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfml and opengl
« Reply #13 on: December 14, 2009, 04:44:29 pm »
What about the samples of the SDK?
Laurent Gomila - SFML developer