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.
That is the reason why. Thanks

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.
#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;
}
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);
}
gl_FrontColor = gl_Color;
gl_Position = gl_ModelViewProjectionMatrix * a;
void main(void)
{
vec4 a = gl_Vertex;
a.x = a.x * 0.5;
a.y = a.y * 0.5;
gl_Position = a;
}
#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;
}
#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;
}
#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;
}