SFML community forums

Help => Graphics => Topic started by: YuGiOhMoDDeR on July 15, 2012, 05:05:15 pm

Title: SFML prob
Post by: YuGiOhMoDDeR 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 :)
Title: Re: SFML prob
Post by: binary1248 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?
Title: Re: SFML prob
Post by: YuGiOhMoDDeR 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
Title: Re: SFML prob
Post by: binary1248 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;
}
Title: Re: SFML prob
Post by: YuGiOhMoDDeR 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 :(
Title: Re: SFML prob
Post by: Laurent 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?
Title: Re: SFML prob
Post by: YuGiOhMoDDeR 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 :(
Title: Re: SFML prob
Post by: binary1248 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?
Title: Re: SFML prob
Post by: YuGiOhMoDDeR 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 :(
Title: Re: SFML prob
Post by: binary1248 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;
}
Title: Re: SFML prob
Post by: YuGiOhMoDDeR on July 16, 2012, 02:10:41 pm
console shows no error, but screen again just blinks n disappears :(
Title: Re: SFML prob
Post by: binary1248 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;
}
Title: Re: SFML prob
Post by: YuGiOhMoDDeR 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 :'(
Title: Re: SFML prob
Post by: binary1248 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.
Title: Re: SFML prob
Post by: Laurent 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.