SFML community forums
Help => Window => Topic started by: newn on August 20, 2010, 07:29:50 pm
-
Hi everyone.
I'm having a little bit of trouble, while compiling the cube code from the official site:
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create the main window
sf::Window App(sf::VideoMode(800, 600, 32), "SFML OpenGL");
// Create a clock for measuring time elapsed
sf::Clock Clock;
// Set color and depth clear value
glClearDepth(1.f);
glClearColor(0.f, 0.f, 0.f, 0.f);
// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
// Resize event : adjust viewport
if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
// Set the active window before using OpenGL commands
// It's useless here because active window is always the same,
// but don't forget it if you use multiple windows or controls
App.SetActive();
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Apply some transformations
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f);
glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
// Draw a cube
glBegin(GL_QUADS);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f( 50.f, 50.f, 50.f);
glVertex3f( 50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(50.f, -50.f, -50.f);
glVertex3f(50.f, 50.f, -50.f);
glVertex3f(50.f, 50.f, 50.f);
glVertex3f(50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, 50.f);
glEnd();
// Finally, display rendered frame on screen
App.Display();
}
return EXIT_SUCCESS;
}
I've linked with sfml-window-s.lib and sfml-system-s.lib files. However, i still get this error:
1>main.obj : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function _main
1>D:\Development\Tests\OpenGL usage\Debug\OpenGL usage.exe : fatal error LNK1120: 1 unresolved externals
So from the past problem, i understand, that this is linking problem. What do i need to link? Logically OpenGL libraries, but still - not sure about that.
P.S. sorry for noobish questions, shame on me, but well, i don't know such stuff yet.
P.S.S. i like SFML, i write the code pretty quick, it's easy to remember for me, i like it more than i did liked Allegro. Although, the OpenGL code was quite... Hard to type and remember. SO great job, developers! :)
-
You have to link to GLU (glu32.lib).
-
Yup, thanks, it's working. Looks pretty cool, that cube, but it puts some strain on the VGA though.
Anyway, great library!
-
sorry for the thread revival, :D
Just has this problem, got it fixed with this thread though.
However, when the window opens, the screen will stay blank white until I move my mouse. Then, if I leave my mouse still, the animation will pause for a few seconds, then update, then pause, then update etc.
If I move my mouse around in the window, the animation is smooth.
Is this supposed to be the case, the movement of my mouse seems to effect the motion of the cube, but I can't see how this could be true.
I have noticed this sort of behaviour on the net, where there is a video, and if you hover over the thumbnail, it runs through a few preview pictures, if I move the mouse around on them, it plays smoothly, if I don't, it usually just stays on the first image.
So basically, is this SFML related and the fact that it does it elsewhere is just a coincidence, or as I'm sarting to think, is there something messed up deeper within my system, (graphics drivers perhaps)?
Thanks, and sorry for the seemingly huge first post, :D