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

Author Topic: [OpenGL - SFML] Error while compiling/debugging  (Read 2031 times)

0 Members and 1 Guest are viewing this topic.

Zeneus

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • Email
[OpenGL - SFML] Error while compiling/debugging
« on: August 07, 2012, 04:33:01 pm »
Hello guys!
I've been off for some time during this summer, to make some decisions to what i'll do when i start off school,
and also decided to make some changes to my way of programming, and what i'll use for it.

So after all this thinking and decision taking (i know it's very dangerous.. but hopefully we all live right? :P )
i decided to learn some more stuff in sfml and opengl (which i'll be using for future projects).
i started the opengl sfml tutorial, i adapted the code to sfml2.0 but i get a very darn stupid error while compiling/debugging..

#include <SFML/Window.hpp>
#include <GL/gl.h>
#include <GL/glu.h>

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.isOpen())
    {
        // Process events
        sf::Event Event;
        while (App.pollEvent(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::Keyboard::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, 0.0f, 0.0f, 0.0f); //<---- Here mapsy mapsy..
        glRotatef(Clock.getElapsedTime(); * 30, 0.f, 0.f, 0.f);
        glRotatef(Clock.getElapsedTime(); * 90, 0.f, 0.f, 0.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;
}
 

the error point is with an arrow in the code.
error:
error: ambiguous overload for 'operator*' in 'Clock.sf::Clock::getElapsedTime() * 50'|
.... any solutions??
i'll check the post after gym :) (arround 20:00)
thanks in advance!
~Zeneus
« Last Edit: August 07, 2012, 04:37:21 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [OpenGL - SFML] Error while compiling/debugging
« Reply #1 on: August 07, 2012, 04:39:06 pm »
There is an up-to-date OpenGL tutorial and example application for SFML 2.0 online, you don't need to adapt an old SFML 1.6 piece of code. And there is also an API documentation for sf::Clock and sf::Time.

:)
Laurent Gomila - SFML developer

Zeneus

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • Email
Re: [OpenGL - SFML] Error while compiling/debugging
« Reply #2 on: August 07, 2012, 04:42:49 pm »
Thanks Laurent!
can you provide me a URL to the tutorial?
i've searched a lot of times and didn't find anything.. 

EDIT:: actually is this it? : http://www.sfml-dev.org/tutorials/2.0/window-opengl.php
        :: i want to test that clock in the opengl part thats why i "tried" to addapt it. thanks again :P
~Zeneus
« Last Edit: August 07, 2012, 04:45:25 pm by Zeneus »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [OpenGL - SFML] Error while compiling/debugging
« Reply #3 on: August 07, 2012, 04:52:23 pm »
Quote
actually is this it? : http://www.sfml-dev.org/tutorials/2.0/window-opengl.php
Yes.

The example application is in the source tree, under "examples/opengl" (you can find it online on github if you haven't downloaded the SFML sources locally).
Laurent Gomila - SFML developer

Zeneus

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • Email
Re: [OpenGL - SFML] Error while compiling/debugging
« Reply #4 on: August 07, 2012, 07:30:47 pm »
Thanks a lot Laurent :))
I think this thread should be locked now :)) Thanks for the quick responds!