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.


Topics - Cyragia

Pages: [1]
1
General / SFML on Linux - Shared Library versions
« on: April 19, 2014, 08:22:14 pm »
Hello,
I'm trying to get the example program (http://www.sfml-dev.org/tutorials/2.1/start-linux.php) to compile and run on my linux box. I'm using ubuntu 13.10 btw.
I downloaded the precompiled shared libraries from here: http://www.sfml-dev.org/download/sfml/2.1/
I followed the tutorial, when I try to link my object file I get this error:
/usr/bin/ld: warning: libGLEW.so.1.5, needed by ./lib/libsfml-graphics.so, not found (try using -rpath or -rpath-link)
./lib/libsfml-graphics.so: undefined reference to `__glewUniform1fARB'
./lib/libsfml-graphics.so: undefined reference to `__GLEW_ARB_shader_objects'
./lib/libsfml-graphics.so: undefined reference to `__glewGetObjectParameterivARB
and a whole bunch more undefined glew references
I know I have the most recent version of glew, so it's just a version mismatch. After looking around on this forum I saw Laurent told someone to just compile SFML on their own pc to get rid of all version mismatches.
He also suggested to not distribute the shared libs along with the program, but seeing as SFML2.1 hasn't yet been incorporated in the ubuntu packages I have no other choice.

Imagine this situation:
I want to create a program with SFML and distribute it, to be used on multiple ubuntu versions or even linux distros.

As stated above I'll have to distribute the shared SFML libs along with the program, but what about the shared glew, jpeg, xlib, ... libs ? If I were to recompile SFML on my system, won't that 'lock' the binary with the versions of those libs I had on my pc at that time ? for example, if I have version 1.8 of some library, and someone tries to run my program but only has version 1.5, will it still work ? And if I compile for version 1.5, will it work for version 1.8 ?

I hope my questions are clear.

2
Graphics / SFML 2.1 and GLEW
« on: October 29, 2013, 05:50:48 pm »
Hello,
I'm making an openGL application using sfml en glew. (I'm using sfml 2.1)
I'm including my own glew headers and linking to both glew  and sfml statically.

When I try to compile my code a get tons of linker errors like this one:
sfml-graphics-s.lib(glew.obj) : error LNK2005: ___glewCopyTexSubImage3D already defined in glew32s.lib(glew.obj)

When I don't link to glew32s.lib I can't use glew myself.
main.obj : error LNK2001: unresolved external symbol _glewInit@0

I have searched the forum and found some glew related topics but none had a solution to my problem.

Any help is appreciated...

3
SFML projects / [Release] Simple Pixel Renderer
« on: September 30, 2012, 01:28:56 pm »
Hello,
Recently i was making something using sfml, and i had to draw lots ( 1000 + ) of little shapes ( 1 - 5 pixels).
When i tried to do this with sprites or lines of length 1, it was super laggy.
After a bit of searching on the forums, I found out that the best way to do something like this, is to render them to a pixelarray, and then loading the complete array to the video memory at once. It was indeed much faster.
So I wrote a simple class which could render induvidual pixels to a buffer. A bit later i added lines, then circles and rectangles.
I noticed quite a lot of people need something like this, so I'm releasing my class to the public :)
I'm not claiming this is the best/fastest way of doing this, neither is this code very optimized, but nonetheless i think a lot of people will find this useful.

If you have suggestions, or found a bug, feel free to tell me !


NOTE: the buffer is meant to cover the whole screen !
If you want to draw anything else, first draw this, then draw your sprites or whatever after it.

usage example :

//initialization
sf::RenderWindow Window(sf::VideoMode(WIDTH, HEIGHT, 32), "Example");
CRenderer Renderer( WIDTH, HEIGHT );

//-------------------------------------

//inside renderer loop

//clear window
Window.Clear();
//clear buffer (optional: choose a color )
Renderer.Clear();

//draw everything you want
Renderer.DrawCircle( 100, 150, 10, sf::Color( 255 ), 0, 0 ), true );
Renderer.DrawPixel( 100, 150, sf::Color( 255 ), 0, 0 ), true );

//draw the buffer to the screen
Renderer.DrawToWindow( Window );

//draw everything else: sprites, images, text, ...

//display window
Window.Display();
       
 

full class:
class CRenderer {

public:

        sf::Uint8* pixelArray;
        int width;
        int height;
        sf::Image ScreenImage;

        CRenderer( int _width, int _height)
        {
                width = _width;
                height = _height;
                pixelArray = new sf::Uint8[ width * height * 4 ];

                for( int i = 0 ; i < width * height * 4 ; i++ )
                {
                        pixelArray[i] = 0x00;
                }

        }

        ~CRenderer()
        {
                delete[] pixelArray;
        }

        void DrawToWindow( sf::RenderWindow& Screen, bool smooth = false ){
                ScreenImage.LoadFromPixels( width , height, pixelArray );
                ScreenImage.SetSmooth( smooth );
                sf::Sprite ScreenSprite( ScreenImage );
                Screen.Draw( ScreenSprite );
        }
        void DrawPixel( int x, int y, sf::Color color ){
                if( ( x >= 0 ) && ( x < width ) && ( y >= 0 ) && ( y < height ) )
                {
                        pixelArray[ (y * width + x)*4 ] = color.r;
                        pixelArray[ (y * width + x)*4 + 1 ] = color.g;
                        pixelArray[ (y * width + x)*4 + 2 ] = color.b;
                        pixelArray[ (y * width + x)*4 + 3 ] = color.a;
                }
        }
        void DrawLine( int x0, int y0, int x1, int y1, sf::Color color ){

                int dx = abs( x1 - x0 );
                int dy = abs( y1 - y0 );
                int sx = 0;
                int sy = 0;

                if( x0 < x1 ) { sx = 1; }else{ sx = -1; }
                if( y0 < y1 ) { sy = 1; }else{ sy = -1; }

                int error = dx - dy;

                while(1)
                {
                        DrawPixel(x0,y0, color);
                        if( x0 == x1 && y0 == y1){ break; }
                        int e2 = 2*error;
                        if( e2 > -dy ){ error = error - dy; x0 = x0 + sx; }
                        if( e2 < dx){ error = error + dx; y0 = y0 + sy; }
                }
        }
        void DrawCircle( int x0, int y0, int r, sf::Color color, bool filled = true )
        {
                int f = 1 - r;
                int ddF_x = 1;
                int ddF_y = -2 * r;
                int x = 0;
                int y = r;

                DrawPixel(x0, y0 + r, color);
                DrawPixel(x0, y0 - r, color);
                if( filled )
                {
                        DrawLine(x0 - r, y0, x0 + r, y0, color);
                }
                else
                {
                        DrawPixel(x0 + r, y0, color);
                        DrawPixel(x0 - r, y0, color);
                }

                while(x < y)
                {
                        if(f >= 0)
                        {
                                y--;
                                ddF_y += 2;
                                f += ddF_y;
                        }
                        x++;
                        ddF_x += 2;
                        f += ddF_x;    
                        if( filled )
                        {
                                DrawLine(x0 + x, y0 + y, x0 - x, y0 + y, color);
                                DrawLine(x0 + y, y0 + x, x0 - y, y0 + x, color);
                                DrawLine(x0 + x, y0 - y, x0 - x, y0 - y, color);
                                DrawLine(x0 + y, y0 - x, x0 - y, y0 - x, color);
                        }
                        else
                        {
                                DrawPixel(x0 + x, y0 + y, color);
                                DrawPixel(x0 - x, y0 + y, color);
                                DrawPixel(x0 + x, y0 - y, color);
                                DrawPixel(x0 - x, y0 - y, color);
                                DrawPixel(x0 + y, y0 + x, color);
                                DrawPixel(x0 - y, y0 + x, color);
                                DrawPixel(x0 + y, y0 - x, color);
                                DrawPixel(x0 - y, y0 - x, color);
                        }
                }
        }

        void DrawRectangle( int x1, int y1, int x2, int y2, sf::Color color, bool filled = true ){
                if( x1 > x2 ){
                        int temp = x1;
                        x1 = x2;
                        x2 = temp;
                }
                if( y1 > y2 ){
                        int temp = y1;
                        y1 = y2;
                        y2 = temp;
                }
                for( int x = x1 ; x < x2 ; x++ )
                {
                        for( int y = y1 ; y < y2 ; y++ )
                        {
                                DrawPixel( x, y, color );
                        }
                }
        }
        void Clear( sf::Color color ){
                for( int i = 0 ; i < width * height ; i++ )
                {
                        pixelArray[ i * 4 ] = color.r;
                        pixelArray[ i * 4 + 1 ] = color.g;
                        pixelArray[ i * 4 + 2 ] = color.b;
                        pixelArray[ i * 4 + 3 ] = color.a;
                }
        }
};
 

4
Graphics / Drawing individual pixels
« on: August 31, 2012, 01:08:38 pm »
Hello,
I'm trying to draw individual pixels to the screen.
First i tried to draw them using line of 1 pixel, it worked but was incredibly slow.
To draw every pixel on a 640x480 screen it takes about 2 seconds...
Then i searched on the forum, and i found out that writing to  a buffer, then loading it with  sf::Image::LoadFromPixels should be much faster.
So i tried that, it worked and it was indeed much faster, i got about 80-90 fps in release mode.
But the pixels i draw look antialiased or something, the pixel i wanted to draw is not fully drawn and some pixels around it are slightly drawn too...
How can i fix this ? i just want one clean pixel to be drawn.
Also, is the way i draw the fps the most efficient way ? if not, what is the most efficient way ?

My code :
#if _DEBUG
        #pragma comment(lib, "sfml-system-s-d.lib")
        #pragma comment(lib, "sfml-window-s-d.lib")
        #pragma comment(lib, "sfml-graphics-s-d.lib")
#else
        #pragma comment(lib, "sfml-system-s.lib")
        #pragma comment(lib, "sfml-graphics-s.lib")
        #pragma comment(lib, "sfml-window-s.lib")
#endif

#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
//#include <Windows.h>
using namespace std;
#include "CRenderer.h"
#include "CParticle.h"
#include "CPhysics.h"

#define WIDTH 640
#define HEIGHT 480

char textBuffer[1024];


int main()
{

        //INITIALIZATION
        sf::RenderWindow Window(sf::VideoMode(WIDTH, HEIGHT, 32), "SFML-Test");
        Window.Create(sf::VideoMode(WIDTH, HEIGHT, 32), "SFML-Test");
        CRenderer Renderer( WIDTH, HEIGHT );
        sf::Image ScreenImage;


        //MAIN LOOP
        while (Window.IsOpened())
        {
               
                // Loop through all the events and handle them
                sf::Event Event;
                while (Window.GetEvent(Event))
                {
                        // Exit when window is close or escape is pressed
                        if ( (Event.Type == sf::Event::Closed) || ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)) )
                                Window.Close();

                        if (Event.Key.Code == sf::Key::F1)
                        {
                                sf::Image Screenshot = Window.Capture();
                                Screenshot.SaveToFile("screenshot.jpg");
                        }
                }
                // Clear the window
                Window.Clear();

                //draw some random stuff
                /*for( int x = 0 ; x < WIDTH ; x++ )
                {
                        for( int y = 0 ; y < HEIGHT ; y++ )
                        {
                                Renderer.DrawPixel( x, y, sf::Color( x % 255, y % 255, x % 255, 255 ) );
                        }
                }*/

                Renderer.DrawPixel( 50, 50, sf::Color( 255, 0, 0 ) );
                ScreenImage.LoadFromPixels( WIDTH , HEIGHT, (sf::Uint8*) Renderer._pixelArray );
                sf::Sprite ScreenSprite( ScreenImage );
                Window.Draw( ScreenSprite );

                // Calculate and draw FPS
                sf::String Text_FPS;
                Text_FPS.SetFont(sf::Font::GetDefaultFont());
                sprintf_s( textBuffer, "FPS: %i", (int)(1.0f / Window.GetFrameTime()) );
                Text_FPS.SetText(textBuffer);
                Text_FPS.SetColor(sf::Color(255, 0, 0));
                Text_FPS.Move(5, 5);
                Window.Draw(Text_FPS);


                // Display window
                Window.Display();

        }

        return EXIT_SUCCESS;
}

class CRenderer {

public:

        __int32* _pixelArray;
        int _width;
        int _height;

        CRenderer( int width, int height)
        {
                _pixelArray = new __int32[width * height];

                for( int i = 0 ; i < width * height ; i++ )
                {
                        _pixelArray[i] = 0x00000000;
                }

                _width = width;
                _height = height;
        }

        ~CRenderer()
        {
                delete[] _pixelArray;
        }

        bool DrawPixel( int x, int y, sf::Color color ){
                __int32 colorTotal = ( ( ( ( color.r ) & 0xff ) << 24 ) | ( ( ( color.g ) & 0xff ) << 16 ) | ( ( ( color.b ) & 0xff ) << 8 ) | ( ( color.a ) & 0xff ) );
                if( ( x >= 0 ) && ( x < _width ) && ( y >= 0 ) && ( y < _height ) )
                {
                        _pixelArray[ y * _width + x ] = colorTotal;
                        return true;
                }
                return false;
        }

};

Pages: [1]
anything