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

Author Topic: [SOLVED] OpenGL tutorial not working.  (Read 5182 times)

0 Members and 1 Guest are viewing this topic.

Viktory

  • Newbie
  • *
  • Posts: 4
    • View Profile
[SOLVED] OpenGL tutorial not working.
« on: March 04, 2012, 08:33:37 am »
So, I read this tutorial:
http://www.sfml-dev.org/tutorials/1.6/window-opengl.php

and compiled it, with the command:
Quote
$ g++ main.cpp -lsfml-window -sfml-system

and I got the output:
Quote
/tmp/cchWQE5i.o: In function `main':
main.cpp:(.text+0x17f): undefined reference to `gluPerspective'
collect2: ld returned 1 exit status

I asked Google and it said that I had to link the OGL libraries, so I tried this:
Quote
$ g++ main.cpp -lglu32 -lopengl32 -lglut32 -lsfml-window -lsfml-system

Which gave me this:
Quote
/usr/bin/ld: cannot find -lopengl32
/usr/bin/ld: cannot find -lglu32
/usr/bin/ld: cannot find -lglut32
collect2: ld returned 1 exit status


So what am I doing wrong, and how do I fix it?
Thanks in advance.

EDIT:
In case you wanted the code:
Code: [Select]

#include <SFML/Window.hpp>

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 don't live up to my name :P

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
[SOLVED] OpenGL tutorial not working.
« Reply #1 on: March 04, 2012, 09:50:35 am »
Assuming you are on Linux, as implied by your use of the command line as opposed to an IDE, link to OpenGL and GLU with -lGL and -lGLU
I use the latest build of SFML2

Viktory

  • Newbie
  • *
  • Posts: 4
    • View Profile
[SOLVED] OpenGL tutorial not working.
« Reply #2 on: March 05, 2012, 05:47:39 am »
Thanks for that, and sorry for my failure to include my platform in the first post  :oops:
i don't live up to my name :P