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

Pages: [1] 2 3 4
General / Re: Common deadzones and axis map for Xbox 360 and PS3 controller
« on: November 12, 2014, 05:24:06 am »
Thanks G. anyone know roughly the deadzones?

General / Common deadzones and axis map for Xbox 360 and PS3 controller
« on: November 11, 2014, 12:03:55 am »
Hello all,

I need to add joystick support in my game and I know that joystick manufacturers handle controllers very differently. I don't have a PS3 and Xbox 360 joystick to test with.

Can anyone tell me what axis is mapped to each part of the controllers and what buttons are which?
Also what the expected deadzone is for these.

Graphics / Re: Can this be done with an OpenGL shader?
« on: September 03, 2014, 07:46:27 am »
I don't know if that is what you were trying to initially do, but with a bit more effort, you can probably attain a result more like the picture in your first post.

Well I think my effect is pretty much what I initially wanted. :)
This is what I was going for:

My ownly visual complaint is how jaggie the edges on my center lines are...

I've tried a few interpolation methods and linear seemed the cheapest CPU wise. I also tried smoothstep and cosine interpolation methods. They were not too much different visually when adding a very soft faint glow around the lines.

Ideally I'd like to be able to send the sf::Shader more than just vertex and color data, I'd like to store the two additional two points for each line inside the polygons. Then I could render all lines in one big pass...

I read something about "striding" across data with shaders where you store more than just vertices and color in an array. As it stands I call the shader once for every single line which I guess might cause some extra overhead?

Then again, I'd hate to be generating huge arrays of packed data to pass to the shader with every frame...

Also the line coordinates I'm passing in don't adapt to transformations which is why you see the 600 - y to correct the coordinates in my code above.

Graphics / Re: Can this be done with an OpenGL shader?
« on: September 02, 2014, 10:27:03 pm »
Ok, as promised I've cobbled together something that appears to work and have tried to document.

The testbed for the shaders...
Code: [Select]
#include <SFML/Graphics.hpp>
#include <cmath>

int main()
  // Create the main window
  sf::RenderWindow window(sf::VideoMode(800, 600), "Glowing Line Shader");

  // Slow down the action since I'm tossing out random lines per frame below

  // Create a new shader object
  sf::Shader line_shader;

  // Set how thick we need the lines
  float thickness = 48.0;

  // Create a container to store the points in for the shader
  sf::VertexArray line_points;

  // Load the vertex shader and also fragment shader
  line_shader.loadFromFile("point.vert", "glow.frag");

  // This shader is for Quads, the lines are actually chubby rectangles

  // The render state will hold blending type and shader
  sf::RenderStates render_attributes;

  // Set the attributes in our sf::RenderStates object
  render_attributes.shader = &line_shader;

  // For a nice healthy glow we use additive blending
  render_attributes.blendMode = sf::BlendAdd;

  // Start the program loop
  while (window.isOpen())
    // Process events
    sf::Event event;
    while (window.pollEvent(event))
      // Close window: exit
      if (event.type == sf::Event::Closed)

      if (event.type == sf::Event::KeyPressed)
        switch (event.key.code)
        // Escape key: exit
        case sf::Keyboard::Escape:


    // Clear the window
    window.clear(sf::Color(0, 0, 0, 255));

    // 30 chubby glowers (recall I've forced the FPS speed to be slow above)
    for(int i = 0; i < 30; ++i)
      // line endpoints/verts , this could be moved to GPU...maybe?
      // Or Geometry shader once they become more common with drivers...
      float x  = static_cast<float>(rand() % 800);
      float y  = static_cast<float>(rand() % 600);
      float x2 = static_cast<float>(rand() % 800);
      float y2 = static_cast<float>(rand() % 600);

      float sub_angle = (2.0 * M_PI) / 8.0;
      float theta = atan2(y2 - y, x2 - x);
      float theta2 = atan2(y - y2, x - x2);
      float radius = .5 * thickness * sqrt(2.0);

      // Make a fat rotated rectangle of points this is HORRID
      float xx = x + cos(theta2 + sub_angle) * radius;
      float yy = y + sin(theta2 + sub_angle) * radius;

      float xx2 = x + cos(theta2 - sub_angle) * radius;
      float yy2 = y + sin(theta2 - sub_angle) * radius;

      float xx3 = x2 + cos(theta - sub_angle) * radius;
      float yy3 = y2 + sin(theta - sub_angle) * radius;

      float xx4 = x2 + cos(theta + sub_angle) * radius;
      float yy4 = y2 + sin(theta + sub_angle) * radius;

      // LOL FUN Kolrs
      sf::Color col_a = sf::Color(rand() % 255, rand() % 255, rand() % 255);
      sf::Color col_b = sf::Color(rand() % 255, rand() % 255, rand() % 255);

      // Put verticies into the line_points buffer
      line_points.append(sf::Vertex(sf::Vector2f(xx2, yy2), col_a));
      line_points.append(sf::Vertex(sf::Vector2f(xx, yy), col_a));
      line_points.append(sf::Vertex(sf::Vector2f(xx3, yy3), col_b));
      line_points.append(sf::Vertex(sf::Vector2f(xx4, yy4), col_b));

      // Shaders use text strings to set their parameters...strange
      line_shader.setParameter("line_width", thickness);

      // SFML does not share OpenGL's coord system now, subtract y pos from 600
      line_shader.setParameter("start", sf::Vector2f(x, 600 - y));
      line_shader.setParameter("end", sf::Vector2f(x2, 600 - y2));

      window.draw(line_points, render_attributes);
    // Finally, display the rendered frame on screen

  return EXIT_SUCCESS;

Code: [Select]
uniform float line_width;
uniform vec2 start;
uniform vec2 end;

float point_distance(vec2 test)
  float A = test.x - start.x;
  float B = test.y - start.y;
  float C = end.x  - start.x;
  float D = end.y  - start.y;

  float dot_p  = A * C + B * D;
  float len_sq = C * C + D * D;
  float param = dot_p / len_sq;

  float xx = 0.0;
  float yy = 0.0;

  if (param < 0.0 || (start.x == end.x && start.y == end.y))
    xx = start.x;
    yy = start.y;
  else if (param > 1.0)
    xx = end.x;
    yy = end.y;
    xx = start.x + param * C;
    yy = start.y + param * D;

  float dx = test.x - xx;
  float dy = test.y - yy;
  return(sqrt(dx * dx + dy * dy));

void main()
    vec4 pixel = gl_Color;
    vec4 pos = gl_FragCoord;

    float dist = point_distance(pos.xy);

    if(dist > line_width * 0.5) // Cut off the corners
      pixel.a = 0.0;
      float intencity = dist / (line_width * 0.5);
      if(intencity < 0.1) // If the fragment is in the closest 10% make it full bright
        pixel.a = mix(1.0, 0.0, intencity);
      else // Interpolate normally
      pixel.a = mix(1.0, 0.0, intencity) * .5;

  gl_FragColor = pixel;

Code: [Select]

//"out" varyings to our fragment shader
uniform float line_width;
varying vec2 vstart;
varying vec2 vend;

void main()
  vec4 vertex = gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ProjectionMatrix * vertex;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_FrontColor = gl_Color;

Graphics / Re: Can this be done with an OpenGL shader?
« on: September 01, 2014, 05:45:52 am »
Yep, looks very close.

I edited their code a bit for asthetics:

Code: [Select]

vec2 rotate(vec2 v, float alpha)
float vx = v.x*cos(alpha)-v.y*sin(alpha);
float vy = v.x*sin(alpha)+v.y*cos(alpha);
v.x = vx;
v.y = vy;
return v;

// lineVecor must be normalized
float distancePointLine(vec2 linePoint, vec2 lineVector, vec2 point)
vec2 linePointToPoint = point-linePoint;
float projectionDistance = dot(lineVector,linePointToPoint);
return length(lineVector*projectionDistance-linePointToPoint);

float distToLineSquare(vec2 p1, vec2 p2, vec2 p, float thickness)
p -= p1;
vec2 lineVector = p2-p1;

float angle = -atan(lineVector.y,lineVector.x);
p = rotate(p,angle);

float dx = 0.0;
dx = abs(p.x);
else if(p.x>length(lineVector))
dx = abs(p.x) - length(lineVector);

return thickness/(dx+abs(p.y));

float distToLineRound(vec2 p1, vec2 p2, vec2 p, float thickness)
float d = length(p-p2);
p -= p1;
vec2 lineVector = p2-p1;

float angle = -atan(lineVector.y,lineVector.x);
p = rotate(p,angle);

d = length(p);
else if(p.x<length(lineVector))
d = abs(p.y);

return thickness/d;

float squareDrop(vec2 p1, vec2 p2, vec2 p, float thickness)
float d = 1.0; //length(p-p2);
p -= p1;
vec2 lineVector = p2-p1;

float angle = -atan(lineVector.y,lineVector.x);
p = rotate(p,angle);

float llv = length(lineVector);
d = 0.1*length(p);
else if(p.x<llv)
d = (llv/(llv-p.x)*0.1)*abs(p.y);

return thickness/d;

float expDrop(vec2 p1, vec2 p2, vec2 p, float thickness)
float d = 1.0; //length(p-p2);
p -= p1;
vec2 lineVector = p2-p1;

float angle = -atan(lineVector.y,lineVector.x);
p = rotate(p,angle);

float llv = length(lineVector);
d = 0.06*length(p);
else if(p.x<llv)
d = exp(10.0*(p.x-0.05))*(llv/(llv-p.x)*0.1)*abs(p.y);

return thickness/d;

void main(void)
vec2 p = gl_FragCoord.xy / iResolution.xx;
vec2 m = iMouse.xy / iResolution.xx;
p -= vec2(0.5,0.5*iResolution.y/iResolution.x);
m -= vec2(0.5,0.5*iResolution.y/iResolution.x);

vec2 o1 = vec2(0.15,0.15);
vec2 o2 = vec2(0.15,0.1);
vec2 o3 = vec2(0.4,0.0);
vec2 o4 = vec2(0.25,0.0);

float angle = 1.0*iGlobalTime;
o1 = rotate(o1,angle);

angle = 2.0*iGlobalTime;
o2 = rotate(o2,angle);
float thickness = 0.002;
float dist = 0.0;
dist += distToLineSquare(o1,o2,p,thickness);
dist += distToLineSquare(o1,-o2,p,thickness);
o1.y *= -1.0;
o2.y *= -1.0;
dist += distToLineRound(o1,o2,p,thickness);
dist += distToLineRound(o1,-o2,p,thickness);
dist += squareDrop(o3,o4,p,thickness*0.5);
dist += expDrop(-o3,-o4*0.5,p,thickness*0.35);
gl_FragColor = vec4(dist*vec3(0.0,0.2,1.0), 0.5);

I've taken binary1248's advice and used his middle method (calculating the distance to each line segment for each passed fragment from some chubby rotated boxes)

I'm kind of hacking on Laurent's examples until I get the result right. Currently I can draw a very fat glowing line of any thickness but need to figure out how to pass all my lines' geometry with ADDITIONAL data. (Laurent's examples don't seem to address varying per polygon data passing, just the geometry points and color).

I've almost got my shader working, I'll post it here for others when I finish. :)

Graphics / Re: Can this be done with an OpenGL shader?
« on: August 19, 2014, 06:19:01 am »
Well I'm kind of stuck with shaders.
It seems like a lot of tutorials mix immediate mode calls with shaders and or insist on using GLUT.

I've downloaded and looked at the shader demonstration for SFML but am still having a hard time figuring it all out. I understand the concept of a textured triangle strip to get those fat glowing lines. I'll include a screen shot and my texture if anyone could just get me started. I've worked with OpenGL a few times before but only using immediate mode. I'm comfortable with translations, rotations in immediate mode etc but those are now deprecated and I'm a bit stuck. I believe this topic is something that people sometimes ask about due to the popularity of the glowing vector look for games.

the attached file "glow.png" is a white gradient texture on a transparent background, might not show on the current forum background.

If anyone has the time to help me get started that would be great. The biggest hurdle for me is just getting the right shaders the right information and calculations. Essentially the middle 32x32 tile gets stretched between the two points of a line and the two endcaps get rotated to make a smooth end...

Graphics / Re: Can this be done with an OpenGL shader?
« on: August 08, 2014, 05:05:12 am »
I'll have to look into fragment shaders!

Graphics / Can this be done with an OpenGL shader?
« on: August 04, 2014, 08:03:33 am »
I have a solid understanding of traditional deprecated OpenGL.
I know that a HUGE chunk of OpenGL will not be supported in the future and I'm expected to adopt OpenGL 3's shader based rendering.

I'd like to create the effect below. Essentially these are lines that glow when they overlap (simple additive blending). I think if I just render all the lines and apply a blurred alpha blended version over the top I'll not get the glowing intersections just a "halo" around the edges.

It seems that to be done correctly each line must be drawn thick then blurred then alpha blended with the ones drawn previously. Does this translate into a OpenGL 3.x shader very well? From what I've read shaders are not usually used on a per line basis taking into account previous lines.

This effect is essential for my project (emulating a Vectrex like display) and I'd like to know how feasable it is before sinking a lot of time into it. I could do it with textured quads (end cap textures and stretched middle texture) but this involves a LOT of calculations for distance, rotation and length on the GPU for each line. I'd rather have the GPU do it.


General / Additive blending with a twist...
« on: July 29, 2014, 08:37:21 am »
I think most here are familiar with additive blending. This is just addition of colors' components to simulate light.

        RED  (255, 0, 0)
+     BLUE (0,     0, 255)
= MAGENTA (255, 0, 255)

It can be used to make things glow when they overlap.

However I find that there are interesting cases, when one channel maxes out and the result is no lighter:
BLUE (0, 0, 255) + BLUE (0, 0, 255) = BLUE (0, 0, 255)

Ideally it would be nice if some of that extra could bleed over proportionately into the other channels
BLUE (0, 0, 255) + BLUE (0, 0, 255) = LIGHT BLUE (128, 128, 255)

Is there a known color mode of blending that describes this?

I don't think SFML has a way to do a custom blending like this but my idea is to not just blend RGB but to add to the overall light "intensity" as colors are added.

Graphics / Stretching a sprite between two points.
« on: January 23, 2012, 05:03:55 pm »

This is not really the same thing. I need to stretch a texture from point a to point b.

Like this.

Graphics / Stretching a sprite between two points.
« on: January 23, 2012, 09:13:47 am »

I'm trying to draw a texture as a line. The texture is 4x8 pixels. It is a gradient for a laser line effect. It points right but that might be the problem.


Also I have a rounded end cap texture that must be rotated and placed at the endpoints. It points right but that might be the problem.


I need a function to rotate and stretch the texture so the edges will touch (x,y) and (x2,y2). Then the end caps are rotated and placed on.

I've messed with this for about 2 hours and between C++'s notion of direction in radians, SFML's notion of direction in degrees, and moving sprite x and y origins. Nothing seems to work.


System / Unicode with cout command...
« on: June 22, 2011, 03:42:09 am »
It looks like I can easily use the character I need directly with my editor.
I really hope they standardize Unicode soon, while I don't understand all of the posts here completely I feel that Unicode really is superior to ASCII.

Thanks for all the help.

System / Unicode with cout command...
« on: June 20, 2011, 06:11:53 am »
This is indeed for Linux. I'm using the GCC compiler with Code::Blocks.
How do I add a unicode character to the sf::String type then output the value of that string to the console window?  :?

Could you provide a simple C++ code example please?

System / Unicode with cout command...
« on: June 20, 2011, 05:22:37 am »

I understand that SFML provides some Unicode functionality.

How would one output some unicode characters to a console using the provided SFML functionality?

My project is terminal based for the Linux platform and I'm writing software to convert images to Unicode characters for image viewing in text only environments.

Help is appreciated thank you. :D

SFML projects / Wireframe contest Graphics Demo
« on: May 24, 2011, 03:11:11 am »
The rules stated that only wireframe objects could be used so my geometry was a bit limited.

I have a huge respect for the vector based games of the 80's.
I might make a 3D multiplayer tribute to Battlezone by Atari.

SFML really is a great windowing context for OpenGL!

Pages: [1] 2 3 4