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

Pages: [1] 2
1
General / Re: Problems with x64
« on: February 08, 2021, 03:11:46 am »
You can delete this, I'm not sure what happened, but I just redid everything and it worked.

2
General / Problems with x64
« on: February 08, 2021, 02:58:47 am »
Hello,

So I've been trying to use the 2.5.1 x64 version and coming across these errors every time

 error C2589: '(': illegal token on right side of '::'
error C2589: '(': illegal token on right side of '::'
 

Which points to:
Rect.inl
////////////////////////////////////////////////////////////
template <typename T>
bool Rect<T>::contains(T x, T y) const
{
    // Rectangles with negative dimensions are allowed, so we must handle them correctly

    // Compute the real min and max of the rectangle on both axes
    T minX = std::min(left, static_cast<T>(left + width));
    T maxX = std::max(left, static_cast<T>(left + width));
    T minY = std::min(top, static_cast<T>(top + height));
    T maxY = std::max(top, static_cast<T>(top + height));

    return (x >= minX) && (x < maxX) && (y >= minY) && (y < maxY);
}

It's weird to me because the x86 version works just fine, as soon as I switch to the 64 it does this. It's the exact same, except for the x64 for x32 linked. I'll also point out that I'm linking statically. I don't remember ever having this problem before, so I must be doing something stupid.

Thanks


3
Graphics / Re: Shaders
« on: January 25, 2021, 01:42:59 am »
Hey!

Thanks, fallahn, I can't believe it was that simple of a mistake!

Unfortunately, I have come across some bugs. One of the player's snake-like character has weird artifacts surrounding it. I've attached a picture. Nothing code-wise has changed except assigning that as a float.

Lastly, could you explain why in this case I don't need to create a sprite and get the RenderTexture's texture and draw it?

Thanks for the help, greatly appreciate it!

PS: I like to learn about these shaders. Do you know of any tutorials to get more familiar with them using SFML as a 2D environment?

EDIT: I noticed moving around the 't.display()' (the render texture) make its work better or worse. At its current spot, it only has artifacts on the right side. So I think it's just placing this in the correct spot?

4
Graphics / Shaders
« on: January 23, 2021, 08:19:12 am »
Hello,

So I'm checking out someone's Tron code from YouTube, which is basically like 2 player Snake. Towards the end he adds in a shader for the 2 players.

#include <SFML/Graphics.hpp>
#include <time.h>
#include <SFML/OpenGL.hpp>
#include <iostream>
using namespace sf;

const int W=600;
const int H=480;
int speed = 4;
bool field[W][H]={0};

struct player
{ int x,y,dir;
  Color color;
  player(Color c)
  {
    x=rand() % W;
    y=rand() % H;
    color=c;
    dir=rand() % 4;
  }
  void tick()
  {
    if (dir==0) y+=1;
    if (dir==1) x-=1;
    if (dir==2) x+=1;
    if (dir==3) y-=1;

    if (x>=W) x=0;  if (x<0) x=W-1;
    if (y>=H) y=0;  if (y<0) y=H-1;
  }

  Vector3f getColor()
  {return Vector3f(color.r,color.g,color.b);}
};

int main()
{
    srand(time(0));

    RenderWindow window(VideoMode(W, H), "The Tron Game!");
    window.setFramerateLimit(60);

    Texture texture;
    texture.loadFromFile("media/Tron/background.jpg");
    Sprite sBackground(texture);

    player p1(Color::Red), p2(Color::Green);

    Sprite sprite;
    RenderTexture t;
    t.create(W, H);
    t.setSmooth(true);
    sprite.setTexture(t.getTexture());
    t.clear();  t.draw(sBackground);

    Font font; font.loadFromFile("F:/Fonts/Sansation.ttf");
    sf::Text text("YOU WIN", font, 35);
    text.setPosition(W / 2 - 80, 20);

    bool Game=true;
    auto shader = new Shader;
    if (!shader->loadFromFile("shader.frag", sf::Shader::Fragment)) std::cout << "Failed to load Shader\n";
    shader->setUniform("frag_ScreenResolution", sf::Vector2f(W, H));
    shader->setUniform("frag_LightAttenuation",100);
    sf::RenderStates states; states.shader = shader;

    while (window.isOpen())
    {
        Event e;
        while (window.pollEvent(e))
        {
            if (e.type == Event::Closed)
                window.close();
        }

        if (Keyboard::isKeyPressed(Keyboard::Left)) if (p1.dir!=2) p1.dir=1;
        if (Keyboard::isKeyPressed(Keyboard::Right)) if (p1.dir!=1)  p1.dir=2;
        if (Keyboard::isKeyPressed(Keyboard::Up)) if (p1.dir!=0) p1.dir=3;
        if (Keyboard::isKeyPressed(Keyboard::Down)) if (p1.dir!=3) p1.dir=0;

        if (Keyboard::isKeyPressed(Keyboard::A)) if (p2.dir!=2) p2.dir=1;
        if (Keyboard::isKeyPressed(Keyboard::D)) if (p2.dir!=1)  p2.dir=2;
        if (Keyboard::isKeyPressed(Keyboard::W)) if (p2.dir!=0) p2.dir=3;
        if (Keyboard::isKeyPressed(Keyboard::S)) if (p2.dir!=3) p2.dir=0;

        if (!Game) {
            window.draw(text);
            window.display();
                continue;
        }

       
        for (int i = 0; i < speed; i++) {
            p1.tick(); p2.tick();
            if (field[p1.x][p1.y] == 1) { Game = false; text.setFillColor(p2.color); }
            if (field[p2.x][p2.y] == 1) { Game = false; text.setFillColor(p1 .color);}
            field[p1.x][p1.y] = 1;
            field[p2.x][p2.y] = 1;

          /*  CircleShape c(3);
            c.setPosition(p1.x, p1.y); c.setFillColor(p1.color);    t.draw(c);
            c.setPosition(p2.x, p2.y); c.setFillColor(p2.color);    t.draw(c);  */

            t.display();
         
            shader->setUniform("frag_LightOrigin", sf::Vector2f{ (float)p1.x,(float)p1.y });
            shader->setUniform("frag_LightColor", p1.getColor());
            t.draw(sprite, states);
            shader->setUniform("frag_LightOrigin", sf::Vector2f{(float) p2.x,(float)p2.y });
            shader->setUniform("frag_LightColor", p2.getColor());
            t.draw(sprite, states);

        }

       ////// draw  ///////
        window.clear();
        window.draw(sprite);
       // window.draw(sf::Sprite{ t.getTexture() });
        window.display();
    }

    return 0;
}
 

And here is the shader itself
uniform vec2 frag_LightOrigin; 
uniform vec3 frag_LightColor;  
uniform float frag_LightAttenuation;   
uniform vec2 frag_ScreenResolution;
uniform sampler2D texture;
void main()
{              
    vec2 baseDistance =  gl_FragCoord.xy;
    baseDistance.y = frag_ScreenResolution.y - baseDistance.y;
    float d = length(frag_LightOrigin - baseDistance);
    float a = 1.0/(frag_LightAttenuation * d); 
    vec4 color = vec4(a,a,a,1.0) * vec4(frag_LightColor, 1.0);  
    vec4 t = texture2D(texture, gl_TexCoord[0].xy);
    if (t[0]>color[0]) color[0]=t[0];
    if (t[1]>color[1]) color[1]=t[1];
    if (t[2]>color[2]) color[2]=t[2];
    gl_FragColor=color;
}
 

He originally was using setParameter and I know that was deprecated so I'm thinking something here is no longer correct? What happens is the screen is just completely green, much like it would be if you used window.clear(sf::Color::Green).

Along with that this was in my console output:
An internal OpenGL call failed in shader.cpp(466).
Expression:
   GLEXT_glUniform1i(binder.location, x)
Error description:
   GL_INVALID_OPERATION
   The specified operation is not allowed in the current state.

One last thing, I changed the casted floats to sf::Vector2i and it was the same, except now it just continued to spam this error in the console box.

Thanks, everyone, hope the beginning of your year has been great.

5
General / Re: Any use 'Tileson' before?
« on: December 10, 2020, 02:49:53 am »
 :-X I didn't even know you can do that.

Thanks!

6
General / Any use 'Tileson' before?
« on: December 08, 2020, 07:54:07 pm »
I'm looking at this cool library that helps parse TileD map editor files.

I'm having one hell of a time trying to figure out how to grab the "Color" property and the values within it? It's sort of like properties within properties.

What I did was make a Tiled Project and added a "Text display" ("Hello World") and I'm trying to obtain the colors that it should parse, so I can set the fillColor of the text. I'm thinking this might have to do with me not being to familiar with std::any and casting around correctly with it (any_cast).

I have basically been doing anything I can with getProps("Color"/"Red"/Text"). When I look at the json file, it breaks down more at "text" so I thought maybe that was how I could get to color.

   {
                 "height":19,
                 "id":27,
                 "name":"TextObject",
                 "rotation":0,
                 "text":
                    {
                     "color":"#00ff00",
                     "text":"Test Map",
                     "wrap":true
                    },
                 "type":"",
                 "visible":true,
                 "width":83,
                 "x":100.625,
                 "y":60
                }],
 
and also trying getProperties() and even tried doing getProperties.get<tson::Colori>(). I'm assuming I'll have to read it into sf::Color as a Uint32? I'm really hoping someone has messed with this before. I'm sure it's really easy and I'm looking past the obvious.



Thanks.
https://github.com/SSBMTonberry/tileson#readme  is the library project and they have some short examples, which I've been trying to pick at in accomplishing this.

I'm going to continue to look at the examples again and hope for the best. Have a great day.

EDIT: The parameters in TileD are  just Color, which breaks down to Red, Green, Blue, Alpha variables.

7
Graphics / Re: Help on an Error after quitting
« on: November 20, 2020, 07:46:57 pm »
Appreciate it, that was the problem. I've had this problem a few times over the years and now that makes complete sense and I did suspect something like that but had no idea why.

Have a good one!

8
Graphics / Help on an Error after quitting
« on: November 19, 2020, 11:49:57 pm »
EDIT: So I decided to use the SFML DLLs instead of statically and I no longer get that error. Could anyone explain to me why that is and how I would correct it if I went back to static?

Hello,

After I close my application I get this error. I'm not sure how to track how I would fix this. I would appreciate some help. It bothers me that it appears every time I close the program, the program itself runs fine.


Unhandled exception at 0x00BFABC4 in DungeonGame.exe: 0xC0000005:
Access violation reading location 0x00000000.

(Brings me to GlContext.cpp)

void GlContext::acquireTransientContext()
{
    // Protect from concurrent access
    Lock lock(mutex);

    // If this is the first TransientContextLock on this thread
    // construct the state object
    if (!transientContext)
        transientContext = new TransientContext;

    // Increase the reference count
    transientContext->referenceCount++;  <----------( X ) 'error here'
}
 

9
General discussions / Keeping PointLight shader centered on player
« on: October 30, 2020, 02:23:55 am »
Hello,

First off, this isn't specifically an SFML question, more of the appropriate math. I hope this is where I am supposed to post this and if not moving it to the correct forum section would be great. I'm not sure if we are supposed to even ask non SFML questions here. So I apologize if the latter is true.

I have been learning about shaders from a spectacular book (highly recommend) "Mastering SFML Game Development" I'm at a point where we are going over dynamic lighting and there is an example with what I believe is called a Point Light.

shader->setUniform("LightPosition",
                               sf::Glsl::Vec3(context->m_wind->GetWindowSize().x / 2.f,
                                              context->m_wind->GetWindowSize().y / 2.f, lightPos.z));
 

Now, it follows the player since the view is centered on the player, to begin with as the world scrolls. But when I get towards the edges of the world and the screen stops scrolling, the player is now offset and not centered on the screen. So I think the best thing to do is use some math to always stick to where the player is and I'm wondering how I could accomplish this correctly?

Thanks, everyone.

PS: I could just check if the view is no longer scrolling and get the offset from the view's center, but I'm more curious about how to solve this mathematically. Something that has hindered me as I improve with game programming.

10
General / Re: Using VertexArray
« on: May 01, 2019, 03:31:12 am »
If your tile size at scale 1 is tileSize, then at scale 128 it's tileSize * 128, which is tileSize * Scale. (sounds huge but whatever)

So basically quads positions would be:
quad[0].position = sf::Vector2f(i * tileSize.x * Scale, j * tileSize.y * Scale);
quad[1].position = sf::Vector2f((i + 1) * tileSize.x * Scale, j * tileSize.y);      
quad[2].position = sf::Vector2f((i + 1) * tileSize.x * Scale, (j + 1) * tileSize.y * Scale);
quad[3].position = sf::Vector2f(i* tileSize.x * Scale, (j+1)*tileSize.y * Scale);

texCoords don't change with scale, if you're using them.

Hey, sorry for the late reply. Thank you very much! This question got lost between the million other places I've asked questions haha. Have a great day.

EDIT: Oh, I forgot to add. Is it true VertexArray is more efficient for big tile maps? Thanks!
EDIT2: I had to * Scale at quad[1] on Y as well. But it works!

11
General / Using VertexArray
« on: April 25, 2019, 02:51:33 am »
Hello,

So I'm messing around with VertexArray for displaying tiles. I've checked out the tutorial example here on the SFML site. I'm trying to figure out how I can scale the tile bigger (for learning and clarity purposes). I can do this just by displaying 1 tile, but when the for loop is involved, I'm a bit confused?

The tiles are 32x32, and the tile sheet provided in the example.

       
sf::Vector2i tileSize{32,32};
float Scale = 128;
...    
for loop(... i < 20 ...)
for loop (... j < 10...)
{
// define it as a rectangle, located at (10, 10) and with size 100x100
quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.x);
quad[1].position = sf::Vector2f((i + 1) * tileSize.x [b]+ Scale[/b], j * tileSize.y);      
quad[2].position = sf::Vector2f((i + 1) * tileSize.x [b]+ Scale[/b], (j + 1) * tileSize.y [b] + Scale[/b]);
quad[3].position = sf::Vector2f(i* tileSize.x, (j+1)*tileSize.y [b]+ scale[/b]);
...
}

I know this must be a simple formula adjustment. I haven't worked with anything like this yet, but I know it's similar to placing a rectangle in OpenGL.

Also, I believe I read something about using a VertexArray for your tilemap improves speed. Something about how it can be turned into one big image? This was before I got into looking at VertexArray (looked too complicated) and I was trying to figure out the best camera culling methods (not sure of the correct term).

Does anyone perhaps have an example of a big map using VertexArray or perhaps even comparing the differences of using a Sprite for each tile? And even more ideal example would be with culling?

Hope that makes sense, and have a great day.

12
That would be awesome. Just to clarify by "right" I mean organized and efficient I should say haha. You got some great stuff, I've been looking at the code all day.

Anyways, thanks! And keep up the great work!

13
I don't know how I found this. I was coding and I went back to my tabs and somehow it "magically" appeared. I must have clicked something and went back to coding while it loaded up (slow internet).

https://dev.my-gate.net/2012/06/21/using-sfview/

I think I googled SFML View examples and found it. I apologize I thought it was part of Official SFML Examples.

That was it, but thanks anyway.

EDIT: I just clicked your blog and went to the exact page I found. So thanks for clarifying!!

EDIT2: eXpl0i3r: I've recently come across a lot of your work. A lot of these examples are super old (2012!), yet they are still relevant today. Do you plan to do any more modern update examples? I believe I saw an engine by you and I really wanted to use it. But these "super buffed up" engine are too intimidating to me. But I've been trying to find a basic setup with tiles (culling, scrolling, state machine, and other simple things and possibly a simple component system). I have enough resources to do it myself, I just really would prefer to have something "done right".

 I just don't like a complex engine that I have no idea how to maneuver around it confidently. So I'd really like to find something simplified but organized and easy to expand on and enough to make a tiny rogue. Any suggestions?

14
Hello,

I remember a year ago there were some code examples for various concepts using SFML. I remember there was this Zelda example where it was demonstrating scrolling/zoom/ and I believe the main concept was using the view. You could toggle split screen, scroll around a pre-rendered map.

It wasn't a game just an example. Somewhere/someone (I believe it was off the SFML github examples) use to provide a bunch of different examples that had the full project source code. I looked at the SFML Wiki, projects, source code, the 100 or so list examples. I can't find all the example codes I once saw a year ago.

Does anyone know where this section is located or what I am even talking about? I'd appreciate it.

Thanks

15
Audio / Re: Audio errors with a book template.
« on: July 25, 2018, 07:33:15 pm »
Sorry eXpl0it3r, I totally forgot I had posted a question. I forgot to bookmark it.

flac.lib came from the SFML winrar file (SFML-2.5.0-windows-vc15-32-bit). Is it not required to run sfml-audio-s correctly? I have since been running the non-static version since I couldn't get this to work with the static version.

I was under the impression I needed to run the dependencies for sfml-audio-s.lib which said sfml-system-s, openal32, flac, vorbisenc, vorbisfile, vorbis, ogg

I have an additional question:
This is with the non-static version. I've been getting this message. It doesn't seem to affect anything, but it does show up. I am running a GT73VR 7RF Titan Pro laptop. Does this have something to do with the lack of speakers?

In the console, since 2.5, I get a message that says
"AL lib: (EE) SetChannelMap: Failed to match front-center channel(2) in channel map.

As I stated, the sound is working fine. I just never came across this until the update.

Pages: [1] 2