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

Pages: [1]
1
General discussions / Console for SFML Devs and players
« on: May 25, 2023, 07:17:43 pm »
I had a crazy idea about making a game console dedicated to 2D/SFML games for awhile now. It should be made to handle SFML the best and be easy to develop for.

Just an idea I had. But I might try to make it a reality as well.

2
Graphics / Textures Container
« on: April 24, 2023, 05:45:37 pm »
A theory:
I've done this with my Xbox homebrew engines that a class contains a list of textures which entities uses by linking a specific texture from the container to the entity's sprite. This way used textures don't get duplicated for a single entity.

Maybe it's already implemented in SFML but if not, here's an idea for you :)

3
Window / Non-OpenGL 3D Rendering
« on: February 15, 2023, 12:58:12 pm »
Hi. I would want to make a 3D library from scratch and use SFML to create the window. How do I do that? Is it possible?

I used this tutorial to learn 3D rendering and want to continue with it.


Thanks. Meerjel01

4
Graphics / Simple 3D Graphics
« on: September 02, 2022, 11:50:00 am »
Quick question.

I want to make a 3D renderer similar to the Marathon engine Aleph One. How do I position primitive vertices to make a 3D polygon?

Please respond. Thanks.

5
Graphics / Ray 1
« on: December 11, 2020, 02:26:37 pm »
Hello. Can I get some help with my raycaster project that's using code from Adventure3D here at the forums. I want to make a more advanced raycaster with polygons and heights like in Bungie's Marathon series and would want to know where to start from here. (Autism is un-helping)

I will give out some code of what I have edited from tms's project if needed. It's been quite awhile with this now.

6
Graphics / Editor Line Problem
« on: May 06, 2020, 03:19:01 pm »
Hey again. I got back into SFML development and are working on an editor for my Raycaster engine. I got the grid and vertex placement via mouse working but I haven't gotten edges(Lines) to work yet.

Here's the editor's main script
int main(int, char const**)
{
   
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window", sf::Style::Resize);
   
    int gridSize = 16;
   
    sf::RectangleShape gridBox(sf::Vector2f(gridSize, gridSize));
    gridBox.setFillColor(sf::Color(0, 0, 0));
   
    MapPoint pnt;
   
    gridBox.setOutlineThickness(1);
    gridBox.setOutlineColor(sf::Color(155, 155, 155));
   
    const int nofRows = 128;
    const int nofCols = 128;
    const int distance = gridSize;
    const float offset = distance/2.f;
    const float height = std::sqrt(std::pow(distance,2.f) - std::pow(offset,2.f));

    sf::Font font;
    if (!font.loadFromFile(resourcePath() + "sansation.ttf"))
    {
        // error...
    }
   
    sf::Texture dotTex;
    if(!dotTex.loadFromFile(resourcePath() + "dot.png"))
    {
        // error...
    }
   
    sf::Text text1;
    sf::Text text2;
   
    text1.setFont(font);
    text2.setFont(font);
    text1.setCharacterSize(8);
    text2.setCharacterSize(8);
    text1.setFillColor(sf::Color::Red);
    text2.setFillColor(sf::Color::Blue);
    text2.setPosition(0, 8);
   
    int currentVertIndex = 0;
    int currentEdgeIndex = 0;
   
    sf::Vector2f firstPointForEdge;
   
    std::vector<Edge> edgeNodes;
    std::vector<Vertex> vertNodes;
    bool addingLine;
   
    // Start the game loop
    while (window.isOpen())
    {
       
        sf::Vector2i pixelPos = sf::Mouse::getPosition(window);
        sf::Vector2f worldPos = window.mapPixelToCoords(pixelPos);
       
       
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window: exit
            if (event.type == sf::Event::Closed) {
                window.close();
            }

            // Escape pressed: exit
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
                window.close();
            }
           
            if(event.type == event.MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left) {
                if(!addingLine) {
                    firstPointForEdge = worldPos;
                    addingLine = true;
                } else {
                   
                    edgeNodes.push_back(*new Edge(firstPointForEdge, worldPos));
                    addingLine = false;
                }
               
                currentVertIndex++;
                vertNodes.push_back(*new Vertex(worldPos));
            }
           
        }
       
       
       
        text1.setString("World point is " + std::to_string(worldPos.x) + " " + std::to_string(worldPos.y));
        text2.setString("Vertices " + std::to_string(vertNodes.size()) + " " + std::to_string(currentVertIndex));

        // Clear screen
        window.clear();

        for (int i=0; i<nofRows; ++i) {
            for (int j=0; j<nofCols; ++j){
                gridBox.setPosition(j*distance, i*height);
                pnt.setPosition(j*distance - 1.5, i*height - 1.5);
                window.draw(gridBox);

            }
        }
       
        for(int x = 0; x < vertNodes.size(); x++) {
            vertNodes[x].onDraw(window);
        }
        for(int x = 0; x < edgeNodes.size(); x++) {
            edgeNodes[x].onDraw(window);
        }
       

        window.draw(text1);
        window.draw(text2);
       
        // Update the window
        window.display();
    }

    return EXIT_SUCCESS;
}
 

And here's the Edge header
#include <SFML/Graphics.hpp>

class Edge : public sf::Transformable
{
public:
   
    Edge(sf::Vector2f pos1, sf::Vector2f pos2)
    {
        line[0] = sf::Vertex(pos1);
        line[1] = sf::Vertex(pos2);
    }
   
    virtual void onDraw(sf::RenderTarget& target) const
    {
        target.draw(line, 2, sf::Lines);
    }
   
    sf::Vertex line[];
};
 
It will not display and can crash the editor. So what do I have to change?

7
General / Vector2i and the Problem
« on: March 09, 2020, 02:14:02 pm »
Hi. I am trying to make a raycasting engine out of the Raycasting 3D Adventure code and got stuck in some code. It's clearly because I don't know enough about SFML or programing outside of Unity, which won't stop me from making my engine.

This is the code so far. Apparently there's no Resize function in SFML Vectors so I removed it from line 73.
Code: [Select]
// Raycasting 3D adventure game, based on http://lodev.org/cgtutor/raycasting.html
// Inspired by seeing https://github.com/TheMozg/awk-raycaster
//
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <stdlib.h>
#include <math.h>
#include <unordered_map>

#include <iostream>
#include <sstream>

#define texWidth 64
#define texHeight 64
#define mapWidth 24
#define mapHeight 24

std::string ConvertToString(int number){
    std::ostringstream buff;
    buff<<number;
    return buff.str();
}

int worldMap[mapWidth][mapHeight]=
{
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,1,1}
};

int main()
{
    sf::Texture texture;
    if (!texture.loadFromFile("data/texture/walls.png")) {
        fprintf(stderr, "Cannot open texture!\n");
        return EXIT_FAILURE;
    }
   
    sf::RenderStates state(&texture);
   
    int w = 1024, h = 576;
   
    double posX = 22, posY = 12;  //x and y start position
    double dirX = -1, dirY = 0; //initial direction vector
    double planeX = 0, planeY = 0.66; //the 2d raycaster version of camera plane
   
    double time = 0; //time of current frame
    double oldTime = 0; //time of previous frame
   
    sf::Uint32 buffr[h][w];
    sf::Vector2i theTexture[8];
    for(int i = 0; i < 8; i++) theTexture[i] (texWidth * texHeight); // I think we need a doctor.
   
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(w, h), "SFML window");
   
    window.setFramerateLimit(60);
    sf::Clock clock = sf::Clock();
    sf::Time fps;
   
    // Start the game loop
    while (window.isOpen()) {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window: exit
            if (event.type == sf::Event::Closed)
                window.close();
           
            // Escape key: exit
            if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
                window.close();
        }
       
        window.clear();
       
        for(int x = 0; x < w; x++)
        {
            //calculate ray position and direction
            double cameraX = 2 * x / double(w) - 1; //x-coordinate in camera space
            double rayPosX = posX;
            double rayPosY = posY;
            double rayDirX = dirX + planeX * cameraX;
            double rayDirY = dirY + planeY * cameraX;
           
            //which box of the map we're in
            int mapX = int(rayPosX);
            int mapY = int(rayPosY);
           
            //length of ray from current position to next x or y-side
            double sideDistX;
            double sideDistY;
           
            //length of ray from one x or y-side to next x or y-side
            double deltaDistX = sqrt(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX));
            double deltaDistY = sqrt(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY));
            double perpWallDist;
           
            //what direction to step in x or y-direction (either +1 or -1)
            int stepX;
            int stepY;
           
            int hit = 0; //was there a wall hit?
            int side; //was a NS or a EW wall hit?
           
            //calculate step and initial sideDist
            if (rayDirX < 0)
            {
                stepX = -1;
                sideDistX = (rayPosX - mapX) * deltaDistX;
            }
            else
            {
                stepX = 1;
                sideDistX = (mapX + 1.0 - rayPosX) * deltaDistX;
            }
            if (rayDirY < 0)
            {
                stepY = -1;
                sideDistY = (rayPosY - mapY) * deltaDistY;
            }
            else
            {
                stepY = 1;
                sideDistY = (mapY + 1.0 - rayPosY) * deltaDistY;
            }
           
            //perform DDA
            while (hit == 0)
            {
                //jump to next map square, OR in x-direction, OR in y-direction
                if (sideDistX < sideDistY)
                {
                    sideDistX += deltaDistX;
                    mapX += stepX;
                    side = 0;
                }
                else
                {
                    sideDistY += deltaDistY;
                    mapY += stepY;
                    side = 1;
                }
                //Check if ray has hit a wall
                if (worldMap[mapX][mapY] > 0) hit = 1;
            }
           
            //Calculate distance projected on camera direction (oblique distance will give fisheye effect!)
            if (side == 0)
                perpWallDist = fabs((mapX - rayPosX + (1 - stepX) / 2) / rayDirX);
            else
                perpWallDist = fabs((mapY - rayPosY + (1 - stepY) / 2) / rayDirY);
           
            //Calculate height of line to draw on screen
            int lineHeight = abs(int(h / perpWallDist));
           
            //calculate lowest and highest pixel to fill in current stripe
            int drawStart = -lineHeight / 2 + h / 2;
            if(drawStart < 0)drawStart = 0;
            int drawEnd = lineHeight / 2 + h / 2;
            if(drawEnd >= h)drawEnd = h - 1;
           
            //choose wall color
            //sf::Color color;
            //switch(worldMap[mapX][mapY])
            //{
            //    case 1:  color = sf::Color::Red;  break; //red
            //    case 2:  color = sf::Color::Green;  break; //green
            //    case 3:  color = sf::Color::Blue;   break; //blue
            //    case 4:  color = sf::Color::White;  break; //white
            //    default: color = sf::Color::Yellow; break; //yellow
            //}
           
            int texNum = worldMap[mapX] [mapY] - 1;
           
            double wallX;
            if(side == 0) wallX = posY + perpWallDist * rayDirY;
            else wallX = posX + perpWallDist * rayDirX;
           
            int texX = int(wallX * double(texWidth));
            if(side == 0 && rayDirX > 0) texX = texWidth - texX - 1;
            if(side == 1 && rayDirX < 0) texX = texWidth - texX - 1;
           
            double step = 1.0 * texHeight / texHeight;
           
            double texPos = (drawStart - h / 2 + lineHeight / 2) * step;
            for (int y = drawStart; y<drawEnd; y++) {
                int texY = (int)texPos & (texHeight - 1);
                texPos += step;
                sf::Uint32 color;
                if(side == 1) color = (color >> 1) & 8355711;
               
            }
           
            //give x and y sides different brightness
            //if (side == 1) {
            //    color = sf::Color(color.r/2, color.g/2, color.b/2);
            //}
           
            //draw the pixels of the stripe as a vertical line
            //verLine(x, drawStart, drawEnd, color);
           
           // sf::Vertex line[2] =
            //{
           //     sf::Vertex(sf::Vector2f(x, drawStart), color),
           //     sf::Vertex(sf::Vector2f(x, drawEnd), color)
            //};
           // window.draw(line , 2, sf::Lines);
           
        }
       
        fps = clock.getElapsedTime();
        float fpsValue = 1000000/fps.asMicroseconds();
        clock.restart();
       
        double moveSpeed = fps.asSeconds() * 5.0; //the constant value is in squares/second
        double rotSpeed = fps.asSeconds() * 3.0; //the constant value is in radians/second
       
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
            //both camera direction and camera plane must be rotated
            double oldDirX = dirX;
            dirX = dirX * cos(rotSpeed) - dirY * sin(rotSpeed);
            dirY = oldDirX * sin(rotSpeed) + dirY * cos(rotSpeed);
            double oldPlaneX = planeX;
            planeX = planeX * cos(rotSpeed) - planeY * sin(rotSpeed);
            planeY = oldPlaneX * sin(rotSpeed) + planeY * cos(rotSpeed);
        }
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
            //both camera direction and camera plane must be rotated
            double oldDirX = dirX;
            dirX = dirX * cos(-rotSpeed) - dirY * sin(-rotSpeed);
            dirY = oldDirX * sin(-rotSpeed) + dirY * cos(-rotSpeed);
            double oldPlaneX = planeX;
            planeX = planeX * cos(-rotSpeed) - planeY * sin(-rotSpeed);
            planeY = oldPlaneX * sin(-rotSpeed) + planeY * cos(-rotSpeed);
        }
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
            if(worldMap[int(posX + dirX * moveSpeed)][int(posY)] == false) posX += dirX * moveSpeed;
            if(worldMap[int(posX)][int(posY + dirY * moveSpeed)] == false) posY += dirY * moveSpeed;
        }
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
            if(worldMap[int(posX - dirX * moveSpeed)][int(posY)] == false) posX -= dirX * moveSpeed;
            if(worldMap[int(posX)][int(posY - dirY * moveSpeed)] == false) posY -= dirY * moveSpeed;
        }
       
        window.display();
        window.clear();
    }
   
    return EXIT_SUCCESS;
}

Help is highly appreciated. Meerjel01

8
Graphics / Sprite Scaler
« on: November 14, 2019, 11:40:27 am »
I would want to make an engine that scales and moves sprites to create a 3D world that bestows of numerous blocks. I've gotten this idea from a Dreamcast home-brewer and would think that this method is more easier than raycasting. I'm aware that I should make 3 axises but I just came back to SFML and are clueless where to begin. So what math am I supposed to learn for this?


Meerjel01 (New name for myself)

9
General / SFML on iMac
« on: May 03, 2019, 04:46:44 pm »
I have installed SFML for my MacBook for some time ago and that worked. However I have not gotten it to work when I tried to get it for my iMac, and it's my primary computer for development at home. I get the error "framework not found sfml-system" on Xcode. What did I do wrong?

I really want to make that Raycaster Engine one day so assist please.
Screamy

10
SFML projects / GunPoint Engine
« on: March 05, 2019, 05:44:06 pm »
I had the plans to make a raycaster engine for awhile now and it would be time to actually begin with it.

The GunPoint engine was inspired by my favourite FPS game "Marathon" which was a 2.5D game like Wolfenstein. (And Doom if I must say it) This engine should have what those old shooters had but it will not feature 5D space like in Marathon. I will go traditional and just make it a simple game engine with polygons, heights, directional sprites and all other of those things you've seen from the classics. The engine is going to be a Mac standalone engine.

I am extremely new at SFML so it might take some time to get this to work. But the thing is that I really wanted to do something like this. The GunPoint engine is my long time dream and it kinda needs to be on the Mac cause PC already have so much as it can bear. But as I said, I'm a real novice at this so I will start from the beginning.

https://lodev.org/cgtutor/raycasting.html

Can someone please help? I really need it.

Pages: [1]
anything