SFML community forums
Help => Window => Topic started by: armaskywalker on February 15, 2012, 12:44:41 pm
-
Hi again :D
I try to run OpenGL test from the tutorial:
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include <GL/glut.h>
////////////////////////////////////////////////////////////
/// 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;
}
But have this error on glut.h:
obj\Debug\main.o||In function `glutInit_ATEXIT_HACK':|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.1\..\..\..\..\include\GL\glut.h|486|undefined reference to `__glutInitWithExit@12'|
obj\Debug\main.o||In function `glutCreateWindow_ATEXIT_HACK':|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.1\..\..\..\..\include\GL\glut.h|503|undefined reference to `__glutCreateWindowWithExit@8'|
obj\Debug\main.o||In function `glutCreateMenu_ATEXIT_HACK':|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.1\..\..\..\..\include\GL\glut.h|549|undefined reference to `__glutCreateMenuWithExit@8'|
obj\Debug\main.o||In function `main':|
C:\Users\arma\Desktop\project\testopenglsfml\main.cpp|33|undefined reference to `gluPerspective@32'|
||=== Build finished: 4 errors, 0 warnings ===|
Thanks again guys :D
-
It seems you aren't linking to "glut32.lib" ?
-
#include <GL/glut.h>
This line is not in the tutorial's code.
If you have linker errors about GLU, link to glu32.
-
It seems you aren't linking to "glut32.lib" ?
solved ;)
i have forgot to link at linker setting:
-lopengl32
-lglu32
-lglut32
And copy dll on project Debug folder :D
excuse me but the documentation is all in English and Italian do not find anything, sometimes I get lost :D
Thanks again