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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - CarbonAsh

Pages: [1]
1
Graphics / [SOLVED] sf::Image -> GLuint
« on: January 12, 2010, 06:14:24 am »
I fixed it.  In case anyone else runs into a similar problem I just had to add these lines after I created the texture and still had it bound:

Code: [Select]

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

2
Graphics / [SOLVED] sf::Image -> GLuint
« on: January 11, 2010, 07:36:52 pm »
I have a codebase that uses GLuints to hold textures and I'm trying to convert it from using SDL for windowing/event/audio/etc to SFML.  However, I cannot seem to get my textures to display correctly.  I've whipped up some code showing how I think you should get a GLuint handle to a texture from an sf::Image.

Right now all it does it fill the entire window with a white square.  If I change the code to use a RenderWindow and sf::Sprite the image draws
fine.

Code: [Select]

#include <SFML/Graphics.hpp>

int main()
{
    sf::Window app(sf::VideoMode(1280,800), "SFML Test");

    app.EnableKeyRepeat(false);
    app.SetActive();

    // opengl initialization
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glViewport( 0, 0, 1280, 800 );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0, 1280, 800, 0, -1, 1 );


    sf::Image pic;
    pic.LoadFromFile("bg01.jpg");

    GLuint bgtext = 0;
    glGenTextures(1, &bgtext);
    glBindTexture(GL_TEXTURE_2D, bgtext);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, pic.GetWidth(), pic.GetHeight(),
        0, GL_RGBA, GL_UNSIGNED_BYTE, pic.GetPixelsPtr());

    bool loop = true;
    while (loop)
    {
        sf::Event e;
        while (app.GetEvent(e))
        {
            if (e.Type == sf::Event::Closed ||
                e.Type == sf::Event::KeyPressed)
                loop = false;
        }

        // Do the drawing
        glClear( GL_COLOR_BUFFER_BIT );
        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();
        glScalef(1280, 800, 0);
        glBindTexture(GL_TEXTURE_2D, bgtext);

        glBegin( GL_QUADS );
            // Top-left vertex (corner)
            glTexCoord2i( 0, 0 );
            glVertex3f( 0, 0, 0 );

            // Bottom-left vertex (corner)
            glTexCoord2i( 0, 1 );
            glVertex3f( 0, 1.0f, 0 );

            // Bottom-right vertex (corner)
            glTexCoord2i( 1, 1 );
            glVertex3f( 1.0f, 1.0f, 0 );

            // Top-right vertex (corner)
            glTexCoord2i( 1, 0 );
            glVertex3f( 1.0f, 0, 0 );
        glEnd();

        app.Display();
    }
}

Pages: [1]