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

Author Topic: SFML prob  (Read 4908 times)

0 Members and 4 Guests are viewing this topic.

YuGiOhMoDDeR

  • Newbie
  • *
  • Posts: 7
    • View Profile
SFML prob
« on: July 15, 2012, 05:05:15 pm »
hello guys...this is my first post here on forums :)

im workin on game project, n im tryin to make window with "Hello Word", but i get error

Code: [Select]
An internal OpenGL call failed in Texture.cpp (327) : GL_INVALID_VALUE , a numeric argument
is out of range
here is the code, it doesn't show any compiler errors.

#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <iostream>
#include <stdio.h>

int main() {
        sf::RenderWindow window(sf::VideoMode(800, 600), "Test Window", sf::Style::Titlebar, sf::ContextSettings(32));
        window.setFramerateLimit(60);
        glEnable(GL_DEPTH_TEST);
        glDepthMask(GL_TRUE);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(90.f, 1.f, 1.f, 500.f);
        sf::Event event;
        while (window.isOpen()) {
                while (window.pollEvent(event)) {
                        if (event.type == sf::Event::Closed)
                                window.close();
                        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
                                window.close();
                        if (event.type == sf::Event::Resized)
                                glViewport(0, 0, event.size.width, event.size.height);
                }
                window.setActive();
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                float x =  sf::Mouse::getPosition(window).x * 200.f / window.getSize().x  - 100.f;
                float y = -sf::Mouse::getPosition(window).y * 200.f / window.getSize().y + 100.f;

                glMatrixMode(GL_MODELVIEW);
                glLoadIdentity();

                window.pushGLStates();
                sf::Text text(L"Hello World!");
                text.setPosition(250.f, 450.f);
                text.setColor(sf::Color(255, 255, 255, 128));
                window.draw(text);
                window.popGLStates();

                window.display();
        }
        return EXIT_SUCCESS;
}

hope someone can help me .... thanks in advance :)

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: SFML prob
« Reply #1 on: July 15, 2012, 06:50:01 pm »
Strange, when I tried to compile and run your code I didn't get any messages or OpenGL errors. What operating system, compiler and graphics hardware are you using?
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

YuGiOhMoDDeR

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: SFML prob
« Reply #2 on: July 15, 2012, 07:03:19 pm »
OS: WinXP SP3
compiler: gcc with mingw (4.6.2)

i can compile it too, without any errors, just when i run it, screen is black, without anythin written on it (i mean on "Hello World")..n in cmd window errors mentioned above :(...i dont kno whts wrong

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: SFML prob
« Reply #3 on: July 15, 2012, 07:39:19 pm »
What graphics card do you have?
Which SFML version do you use?

What happens when you compile and run this?:
#include <SFML/Graphics.hpp>

int main() {
        sf::RenderWindow window( sf::VideoMode( 800, 600 ), "Test Window" );
        window.draw( sf::Text( L"Hello World!" ) );
        window.display();
        return 0;
}
« Last Edit: July 15, 2012, 11:07:14 pm by binary1248 »
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

YuGiOhMoDDeR

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: SFML prob
« Reply #4 on: July 15, 2012, 08:24:42 pm »
graphic card: Intel 82485G
SFML version 2- RC

#include <SFML/Graphics.hpp>

int main() {
        sf::RenderWindow window( sf::VideoMode( 800, 600 ), "Test Window" );
        window.draw( sf::Text( L"Hello World!" ) );
        window.display();
        return 0;
}

n when i compile this, window just blinks n disappear :(

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML prob
« Reply #5 on: July 15, 2012, 08:57:27 pm »
Line 327 is
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels)
It can't fail. Are your graphics drivers up to date?
Laurent Gomila - SFML developer

YuGiOhMoDDeR

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: SFML prob
« Reply #6 on: July 15, 2012, 09:07:34 pm »
yes, my drivers are up to date...i also work with irrlicht...i have no probs with it, just wanted to give a shot with SFML..i hope i will find some solution :(

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: SFML prob
« Reply #7 on: July 15, 2012, 09:32:23 pm »
n when i compile this, window just blinks n disappear :(
So there is no error message on the console?
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

YuGiOhMoDDeR

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: SFML prob
« Reply #8 on: July 15, 2012, 09:50:29 pm »
Code: [Select]
So there is no error message on the console?
same error as before...sorry i forgot to mention it in rpevious post :(

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: SFML prob
« Reply #9 on: July 15, 2012, 11:21:55 pm »
What happens (output on console) when you run this?

#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <iostream>

void CheckError( const char* msg ) {
        GLint error = glGetError();

        if( error != GL_NO_ERROR ) {
                std::cout << msg << "\nError: " << error << "\n";
        }
}

int main() {
        char data[4];
        GLuint texture;

        sf::Window window( sf::VideoMode( 800, 600 ), "Test Window" );
        CheckError( "Error in sf::Window" );

        glEnable( GL_TEXTURE_2D );
        CheckError( "Error in glEnable" );

        glGenTextures( 1, &texture );
        CheckError( "Error in glGenTextures" );

        glBindTexture( GL_TEXTURE_2D, texture );
        CheckError( "Error in glBindTexture" );

        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
        CheckError( "Error in glTexImage2D" );

        glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, data );
        CheckError( "Error in glTexSubImage2D" );

        glDeleteTextures( 1, &texture );
        CheckError( "Error in glDeleteTextures" );

        return 0;
}
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

YuGiOhMoDDeR

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: SFML prob
« Reply #10 on: July 16, 2012, 02:10:41 pm »
console shows no error, but screen again just blinks n disappears :(

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: SFML prob
« Reply #11 on: July 16, 2012, 06:30:39 pm »
console shows no error, but screen again just blinks n disappears :(
Don't be sad, it's supposed to blink and disappear :P. Having an event loop makes the tests more complicated than they have to be. At least the fact that it shows no error rules out the possibility that it is hardware/driver related. Next step is to see if SFML managed textures work.

Try this code and see if any error messages show up:
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main() {
        sf::Window window( sf::VideoMode( 800, 600 ), "Test Window" );
        sf::Image image;
        image.create( 2, 2, sf::Color::Cyan );
        sf::Texture texture;
        texture.loadFromImage( image );
        texture.bind();
        return 0;
}
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

YuGiOhMoDDeR

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: SFML prob
« Reply #12 on: July 16, 2012, 09:13:31 pm »
Code: [Select]
Don't be sad, it's supposed to blink and disappear :Pdont scare me maaaan :P

i compiled code, n same thing again....no errors in console, n window blinks n disappears :(

EDIT: i came accross one of simplest tuts for sfml on http://sfmlcoder.wordpress.com/2011/05/20/a-minimal-sfml-program/

n i copy/paste code tht has been used in tutorial...n it works :).....now i dont get why this works, n other dont wanna work :'(
« Last Edit: July 16, 2012, 09:20:23 pm by YuGiOhMoDDeR »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: SFML prob
« Reply #13 on: July 16, 2012, 10:21:02 pm »
Just wild guesses:
glViewport(0, 0, event.size.width, event.size.height);
Don't do that. SFML can report 0 width and height which will produce an GL_INVALID_VALUE error. I remember I found out about this when working on the SFGUI renderer.

sf::ContextSettings(32)
Try leaving this out and see what happens. Your GPU might not support 32-bit depth buffers.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML prob
« Reply #14 on: July 16, 2012, 10:25:42 pm »
Quote
SFML can report 0 width and height
You should have reported it, this is clearly a bug. The original code is therefore ok, it's even shown in the OpenGL tutorial.
Laurent Gomila - SFML developer