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 - reDo

Pages: [1] 2 3 ... 7
1
Graphics / Re: Text does not render
« on: October 17, 2013, 06:32:42 pm »
Oh, I do not know that. I was used to use default but I couldn t find it in 2.1. :D That is the reason why. Thanks

2
Graphics / Text does not render
« on: October 17, 2013, 05:29:45 pm »
I switched to new computer with Win 7 64bit(SFML 2.1) from Win XP 32bit(SFML 2.0) and now i cannot render text, I always got only black screen. Here is code:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600, 32), "");
    window.setFramerateLimit(60);

    while(window.isOpen())
    {
        sf::Event event;
        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();
        }

        sf::Text text;
        text.setString("hello");
        text.setColor(sf::Color::Red);
        window.clear();
        window.draw(text);
        window.display();
    }

    return 0;
}
 

3
Graphics / Re: Image and OpenGL does not work
« on: November 28, 2012, 10:31:14 am »
No, I do not implement or use any prebuilded lighting, I am sure, I think it is caused by the mipmapping  ;)

4
Graphics / Re: Image and OpenGL does not work
« on: November 28, 2012, 06:52:42 am »
I do not have any lighting there  :D . I had sf::Texture in the first, but I have to change quality so I have to use sf::Image.

// EDIT I have just changed the image size from 204x204 to 128x128 and it works good now :D.

5
Graphics / Image and OpenGL does not work
« on: November 27, 2012, 08:21:14 pm »
Hi, I am using Image as texture source from .tga file but it does not work correctly. One texture is working great, but the second, that is loaded first, is showing only by going closer. Where can be the problem please? :-\
sf::Image image;
                image.loadFromFile(matProp.textureFile);
                GLuint generatedTex = 0;
                glGenTextures(1, &generatedTex);
                glBindTexture(GL_TEXTURE_2D, generatedTex);
                glTexImage2D(GL_TEXTURE_2D,
                             0,
                             GL_RGBA,
                             image.getSize().x,
                             image.getSize().y,
                             0,
                             GL_RGBA,
                             GL_UNSIGNED_BYTE,
                             image.getPixelsPtr());
                //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
                //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
                glGenerateMipmap(GL_TEXTURE_2D);
                matProp.texture = generatedTex;

6
Graphics / Re: Shader and render texture
« on: April 24, 2012, 03:20:33 pm »
Thanks that is what I was searching for  :).

7
Graphics / Re: Shader and render texture
« on: April 23, 2012, 07:30:34 pm »
I wanna create something like lighting with multiple lights. Here is picture how it looks with one light. But I wanna use multiple lights with using shaders for it. I have std::vector of lights as you can see in my code and I wanna render all lights from vector with calling shader with different properties for each light. All rendering is done to render texture and here is the problem. I dont know how to call one shader for the render texture without passing a picture that is modified. So I wanna apply light shader with different properties on background image in render texture. Do you understand know :D?

8
Graphics / Re: Shader and render texture
« on: April 23, 2012, 03:45:14 pm »
Thanks that solved this problem  :D but the main is still unsolved.

9
Graphics / Shader and render texture
« on: April 22, 2012, 08:42:20 pm »
Hi, I want to create something like lights with using the shaders, but I do not know how to use one shader with different properties on the same render texture. I want to use it like "cycle for". Please can you tell me how to do this or another way? And I have another problem, now when I am drawing background image to the render texture, it is flipped vertically.
My code
Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <cstring>
#include <vector>

class CLight
{
    public:
        sf::Vector2f position;
        sf::Color color;
        float radius;

        CLight(sf::Vector2f pos, sf::Color col, float rad)
        {
            position = pos;
            color = col;
            radius = rad;
        }
};

int main()
{
    sf::RenderWindow App(sf::VideoMode(800,600,32),"SFML");
    App.setFramerateLimit(60);

    std::vector<CLight> lights;
    lights.push_back(CLight(sf::Vector2f(400,300), sf::Color(128,128,128), 200.f));

    sf::RenderTexture renderTexture;
    renderTexture.create(800,600);

    sf::Texture backTex;
    backTex.loadFromFile("image.png");
    backTex.setSmooth(false);
    sf::Sprite background(backTex);

    sf::Shader fragShader;

    if(!fragShader.loadFromFile("light.frag",sf::Shader::Fragment))
        App.close();

    fragShader.setParameter("texture", backTex);
    while(App.isOpen())
    {
        sf::Event event;
        while(App.pollEvent(event))
        {
            if((event.type == sf::Event::Closed) || (event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
                App.close();
        }

        float mouseX = float(sf::Mouse::getPosition(App).x);
        float mouseY = float(sf::Mouse::getPosition(App).y);

        std::cout<<mouseX<<" "<<mouseY<<std::endl;

        App.clear();
        renderTexture.clear();

        fragShader.setParameter("lightRad", lights[0].radius);
        fragShader.setParameter("lightPos", lights[0].position.x, 600.f-lights[0].position.y);
        fragShader.setParameter("lightCol", lights[0].color.r/255.f, lights[0].color.g/255.f, lights[0].color.b/255.f);

        sf::RenderStates shader(&fragShader);
        renderTexture.draw(background, shader);

        sf::Sprite drawTexture(renderTexture.getTexture());
        App.draw(drawTexture);

        App.display();
    }

    return 0;
}

Shader
Code: [Select]
uniform sampler2D texture;

uniform float lightRad; //radius
uniform vec2 lightPos; //position
uniform vec3 lightCol; //color

void main(void)
{
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
float dis = 1.0f - distance(vec2(gl_FragCoord), lightPos) / lightRad;
vec4 light = vec4(lightCol.r,lightCol.g,lightCol.b,dis);

vec4 col = pixel + light;
gl_FragColor = vec4(col.xyz, dis);
}

10
Graphics / SFML2 and Vertex Shader problem
« on: March 08, 2012, 09:42:02 pm »
I solved my problem. I had to add this line code at the end of the shader.   :D
Code: [Select]
gl_FrontColor = gl_Color;
I am sorry for my mistake and the surplus topic. :oops:

11
Graphics / SFML2 and Vertex Shader problem
« on: March 06, 2012, 09:36:00 am »
Hi, I am real beginner in GLSL. I have this GLSL vertex shader and it doesnt work as I want. According to me it should change the position of the rectangle by * 0.5, because SFML draw it like GL_QUAD with vertexes, but rect disapears. Can somebody help me please?
I also tried change last line to, but it doesnt work :( .
Code: [Select]
  gl_Position = gl_ModelViewProjectionMatrix * a;
Shader code
Code: [Select]
void main(void)
{
   vec4 a = gl_Vertex;
   a.x = a.x * 0.5;
   a.y = a.y * 0.5;

   gl_Position = a;
}

Here is my code
Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main()
{
    sf::RenderWindow App(sf::VideoMode(800,600,32),"SFML");
    App.SetFramerateLimit(30);

    sf::Shader vertShader;

    if(!vertShader.LoadFromFile("scaleshader.vert",sf::Shader::Vertex))
        App.Close();

    while(App.IsOpen())
    {
        App.Clear();
        sf::Event event;
        while(App.PollEvent(event))
        {
            if((event.Type == sf::Event::Closed) || (event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape))
                App.Close();
        }

        sf::RenderStates shader(&vertShader);
        sf::RectangleShape rect(sf::Vector2f(200,100));
        rect.SetPosition(300,250);
        rect.SetFillColor(sf::Color(255,0,0,255));

        App.Draw(rect,shader);

        App.Display();
    }

    return 0;
}

12
Graphics / class sf::Sprite has no member named GetGlobalBounds SFML2.0
« on: January 01, 2012, 07:26:32 pm »
Recompiling latest verison helped :)

13
Graphics / class sf::Sprite has no member named GetGlobalBounds SFML2.0
« on: December 30, 2011, 07:24:47 pm »
I have SFML 2.0, and I have this code, but it says error
 'class sf::Sprite' has no member named 'GetGlobalBounds'|
what am I doing wrong please?
Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow App(sf::VideoMode(800,800,32),"SFML");
    App.SetFramerateLimit(60);
    sf::Texture Tex;
    Tex.LoadFromFile("quad.png");
    Tex.SetSmooth(false);
    sf::Sprite pic(Tex);
    pic.SetOrigin(50,50);
    float x=400, y=300;
    pic.SetPosition(x,y);
    float angle=0;
    while(App.IsOpened())
    {
        App.Clear();
        sf::Event event;
        while(App.PollEvent(event))
        {
            if((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape)) App.Close();
            if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Left))
                angle--;
            if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Right))
                angle++;
        }
        pic.SetRotation(angle);
        App.Draw(pic);
        sf::FloatRect c = pic.GetGlobalBounds();
        App.Display();
    }

    return 0;
}




14
Graphics / Points of my rotated picture
« on: September 18, 2011, 10:46:00 am »
I tried this but after few pressed arrows my rect1(picture that I need to check collision) was gone from the screen. :(
rect1.png = R1 is normal picture 100x200.
Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <cmath>

typedef sf::Vector2f VECTOR;

VECTOR rect1[4] = {VECTOR(400,200),VECTOR(500,200),VECTOR(500,400),VECTOR(400,400)};
//VECTOR rect2[4] = {VECTOR(350,200),VECTOR(450,200),VECTOR(450,400),VECTOR(350,400)};

void DrawRect(sf::RenderWindow & App, const VECTOR rect[], int r, int g, int b)
{
    for(int i=0;i<4;i++)
        App.Draw(sf::Shape::Line(rect[i].x,rect[i].y,
                                 rect[i+(i==3? -3 : 1)].x,rect[i+(i==3? -3 : 1)].y,1,sf::Color(r,g,b)));
}

int main()
{
    sf::RenderWindow App(sf::VideoMode(800,600,32),"Vector");
    sf::Texture imgR1;
    imgR1.LoadFromFile("rect1.png");
    imgR1.SetSmooth(false);
    sf::Sprite R1(imgR1);
    R1.SetPosition(200,200);
    R1.SetOrigin(0,0);
    int angle=0;
    R1.SetRotation(angle);

    App.SetFramerateLimit(60);
    while(App.IsOpened())
    {
        sf::Event Event;
        App.PollEvent(Event);

        if(Event.Type == sf::Event::Closed)
            App.Close();
        if(Event.Key.Code == sf::Keyboard::Escape)
            App.Close();

        if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Right))
        {
            R1.SetRotation(angle--);
            rect1[0] = R1.TransformToGlobal(rect1[0]);
            rect1[1] = R1.TransformToGlobal(rect1[1]);
            rect1[2] = R1.TransformToGlobal(rect1[2]);
            rect1[3] = R1.TransformToGlobal(rect1[3]);
        }
        if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Left))
        {
            R1.SetRotation(angle++);
            rect1[0] = R1.TransformToGlobal(rect1[0]);
            rect1[1] = R1.TransformToGlobal(rect1[1]);
            rect1[2] = R1.TransformToGlobal(rect1[2]);
            rect1[3] = R1.TransformToGlobal(rect1[3]);
        }

        App.Clear();

        DrawRect(App,rect1,255,0,0);
        App.Draw(R1);

        App.Display();

    }

    return 0;
}

15
Graphics / Points of my rotated picture
« on: September 17, 2011, 07:25:05 pm »
But I am asking, is some way how to get coordinates of these four points directly through SFML? I dont understand how to use that rotation matrix, so I will try to make it with sin and cos.  :)

Pages: [1] 2 3 ... 7