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 - Me-Myself-And-I

Pages: [1] 2
1
Hello. I'm trying to implement dragndrop files functionality into my sf::window for windows 11 using the window handle and WINAPI. So far I have this but it doesn't do anything. The window shows it allows dragndrop but it doesn't receive any path to the dropped files.

int main(int argc,char* argv[])
{
       
               
       
       
        IntRect workarea;
        workarea=getWorkArea();
        RenderWindow window(VideoMode(workarea.width,workarea.height),"Desk Engine",Style::None);
        window.setPosition(Vector2i(0,0));     
       
        //Set SFML to allow dragNdrop and hide from taskbar.
        WindowHandle handle = window.getSystemHandle();
        SetWindowLongPtrA(handle,GWL_EXSTYLE,WS_EX_ACCEPTFILES|WS_EX_TOOLWINDOW);

        DragAcceptFiles(handle, TRUE);
       
        while(window.isOpen())
        {
               
                Event e;
                while(window.pollEvent(e))
                {
                        if(e.type==Event::Closed)
                                window.close();
                }
               
                //Handle DRAG and DROP
                MSG msg;
        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_DROPFILES)
            {
                HDROP hDrop = (HDROP)msg.wParam;
                char filePath[MAX_PATH];
                DragQueryFileA(hDrop, 0, filePath, MAX_PATH);
                DragFinish(hDrop);
                cout << filePath << endl;
            }
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
       
        //render stuff
}
 
Thanks in advance!

2
Audio / Music.setVolume doesn't work.(SOLVED)
« on: August 28, 2024, 09:31:56 pm »
For some unknown reason sf::music.setVolume() does not work at all. I'm sure its being called since It printed a test word to the console from the line of code directly before the function.
I saw that someone else had this problem here https://en.sfml-dev.org/forums/index.php?topic=20657.0 so I tried updating to the latest SFML with GCC 13. It still doesn't change the volume when it should. I have made this minimal example.

The following code gets run in the main loop after the music has been set.


cout<<"test"<<endl;
music.setVolume(0);

 

I'm guessing its either a problem with how I linked up SFML or a problem with SFML itself.

3
General / Trouble building SFML from source.
« on: August 26, 2024, 07:37:00 pm »
Hello. I tried building SFML from source and ran into some errors. After generating the mingw makefile using cmake I tried building the library using "mingw32-make install".

[  0%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Clock.cpp.obj
C__~1.EXE: error: unrecognized command line option '-Wnull-dereference'
C__~1.EXE: error: unrecognized command line option '-Wmisleading-indentation'
C__~1.EXE: error: unrecognized command line option '-Wduplicated-cond'

Help would be greatly appreciated. :)

4
Code: [Select]
result=SetWindowLongPtrA(handle,GWL_EXSTYLE,WS_EX_LAYERED|WS_EX_TOOLWINDOW);

if(result==0)
{
MessageBox(handle,"Error","Error",MB_OK);
}

SetWindowPos(handle,HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);


SetLayeredWindowAttributes(handle,RGB(255,0,255),0,LWA_COLORKEY);


Any ideas why this doesn't work on windows 7? The winapi documentation said something about "The SetWindowLongPtr function fails if the process that owns the window specified by the hWnd parameter is at a higher process privilege in the UIPI hierarchy than the process the calling thread resides in." Could this be a possible reason for not allowing transparency?

5
General / How to include SFML for building SFGUI in cmake?
« on: August 11, 2024, 04:41:20 am »
I'm trying to build SFGUI using cmake but it gives me an error that it couldn't find SFMLConfig.cmake and sfml-config.cmake. I'm sure this is just some simple noob mistake so could someone please point out to me how to properly include SFML for this? Thankyou

6
Audio / sf::sound causes severe performance lag.
« on: May 30, 2024, 03:46:49 pm »
I'm having trouble getting around this. If I play a simple sound it always makes the program lag. Is there something that i'm doing wrong with sf::Sound?

I have a simple script that happens only once.
                buffer[4].loadFromFile("ASSETS/thunder.wav");
                sound[4].setBuffer(buffer[4]);
                sound[4].play();
 
Its only an array of 10 sounds and an array of 10 buffers. Any clues as to why it causes a lag? More specifically, I notice a definite lag in graphics when this happens.

7
General / Can you integrate allegro into an sfml window?
« on: May 13, 2024, 02:46:11 pm »
Hey, everybody.

I've been thinking sfml isn't up to the task for video playing so I thought i'd use allegro just for the videos. I want  to have the video display in the sfml window but I'm not sure if this works. I don't know allegro. I don't even have it set up yet. But I would like to find out if its even possible to do this before I waste time on allegro. I know allegro and sfml are built on opengl so there is some possibility.
Thanks

8
Graphics / What is the best way to animate large frames?
« on: April 29, 2024, 01:45:07 am »
I have a class called "Life" which loads each frame into a vector of images and plays it when needed. I need something that can load 960x540 frames so I surely abandoned trying to use spritesheets. This method i'm using now works but is extremely inefficient. Just using the load function causes the entire program to stop till the process of loading finishes. 10 or so frames causes a 1/2 second pause and any decent length animation of 200 frames  causes a whopping 10 to 15 second lag. Of course I can't have this. Is this method impossible? I know there must be some way to load and play the frames of an animation that is 960x540. I just don't know how.


Here is my loading code.
                DIR *dr;
               
                struct dirent *en;
               
                dr=opendir(folder.c_str());
                for(int a=1;a<2000;a++)
                {

                        if(en=readdir(dr))
                        {
                                if(en->d_name==NULL)
                                {
                                        break;
                                }
                                if(a>2)
                                {
                                        Image newimage;
                                        newimage.loadFromFile(folder+en->d_name);
                                        image.push_back(newimage);
                                }
                        }
                        else
                                break;
                               
                               
                }
                closedir(dr);
 

I'm sure its not dirent that is causing the process pause because I manually loaded each frame to test if it was dirent or not and it still halted the processing the same.

I also tried loading only portions at a time as needed by loading the next few frames as needed. This still caused a 1/2 second lag that happened every few frames.



I know that loading from files is not good on performance, since several have told me that before. So I'm looking for either a new method,or a fix to this current method. So any ideas?

I also would like to know if it  would work to load into each image one loop at a time instead of all in one for() iterator.

 

9
Audio / (SOLVED)Music not playing even though its loaded.
« on: April 23, 2024, 12:43:38 am »
I have this strange problem where the music is loaded but nothing happens when the program is run.

This is put before my window.isOpen() loop.
        Music themusic;
        if(!themusic.openFromFile("ASSETS/snow.wav"))
        {
                MessageBox(NULL,"Not found","Error",MB_OK);

        }
        themusic.setVolume(100);
        themusic.play();


The game updates fine.Theres no freezing going on.And I'm sure the audio file works.I have been using audio files in music and suddenly it doesn't make a sound.I'm sure my computer audio works too because sf::sound works. Either i'm doing something wrong here or something in my other code is stopping themusic. I'm certain there is no themusic.stop() anywhere in my code so i'm wondering if its some sort of problem with sfml. I did use 500 sounds. Could this effect sf:Music? I know. Why use 500 sounds? Well its actually for a sound that is played very fast so I need it.
Any ideas where the problem is?
Thanks

10
Graphics / (solved)invisible window border causes smaller top of window
« on: February 04, 2024, 08:40:27 pm »
I have a program that gets the desktops workarea size then makes a window with that size and it works good for displaying the window as large as the screen and not cover up the taskbar but either this or sfml's window class is causing a transparent border to shrink the window at the top.

Here's my code:



IntRect getWorkArea()
{
        RECT rcWorkArea = { 0 };
        SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWorkArea, 0 );
        return IntRect(int(rcWorkArea.left),int(rcWorkArea.top),int(rcWorkArea.right),int(rcWorkArea.bottom));
}


int main()
{
        IntRect workarea;
        workarea=getWorkArea();
        RenderWindow window(VideoMode(workarea.width,workarea.height),"Blupi Desktop",Style::None);
       
       //loop stuff
}
 

11
Hello all.

I know I have asked about this before but I still haven't found a solution. My biggest problem is trying to load dimentionally large animations into a game without causing performance lagging or having an overabundance of texture objects. If I put any large dimention animations into a spritesheet its too large to load to texture. Recently I heard something about it being possible to load large textures using vertices. Is this correct? If so, How? My game isn't so dimentionally large.Its only 960x540 at most. There must be a way to display large frames without hitting performance issues. If I split up an animation thats large into dimentionally small frame rects and save each as files,and load each into the game,it still requires either loading a lot into memory or lloading from file as its needed. Loading from file as needed definitely causes lag I know.  Would it be possible to create several textures when they are needed for preloading and delete them after its done playing the animation?Or would this still cause lag?Also I know that each texture is loaded into memory anyways so why can't it treat one large image as memory the same way that it treats several loaded images as the same amount of memory?

12
Graphics / Image doesn't save but gives no error report.
« on: November 16, 2023, 05:21:37 am »
I searched and searched for an existing topic about this problem because I think I made a similar topic previously. I just couldn't find it.
 
I keep running into this problem every time I make a program that is manipulating images.
Eventually the image does not save as a file and no error report shows up. I just can't figure why it doesn't save. Previous attempts have shown extreme flippancy by influence of non related changes that only sometimes fix it every other time it runs. With this specific program I'm not experiencing any flippancies yet.



string sframe[100];
int numberOfFrames;
RectangleShape shape;
Crop::loadcrop(string filetype)
{
       
        ifstream framelist("frames/frame list.txt");
        for(int a=0;a<100;a++)
        {
                getline (framelist,sframe[a]);
               
                if(sframe[a]=="")
                {
                        numberOfFrames=a-1;
                        break;
                }
                sframe[a]+=filetype;
        }
       
        shape.setOutlineColor(Color::Red);
        shape.setFillColor(Color::Transparent);
        shape.setOutlineThickness(2.f);
        shape.setSize(Vector2f(0,0));
}

int  currentframe=0;
Texture texture;
Sprite sprite;
IntRect rect[100];
IntRect selectrect;
bool firstclick=false; 
bool firsttap=false;   
Crop::setcrop(RenderWindow &window)
{
        if(currentframe<numberOfFrames)
        {
                texture.loadFromFile("frames/"+sframe[currentframe]);
                sprite.setTexture(texture);

                Vector2f MPosition=window.mapPixelToCoords(Mouse::getPosition(window));
               
                if(Mouse::isButtonPressed(Mouse::Left))
                {
                        shape.setPosition(MPosition.x,MPosition.y);
                       
                }
                if(Keyboard::isKeyPressed(Keyboard::Space))
                {
                        shape.setPosition(MPosition.x-shape.getSize().x,MPosition.y-shape.getSize().y);
                }
                shape.setSize(Vector2f(MPosition.x-shape.getPosition().x,MPosition.y-shape.getPosition().y));
                selectrect=IntRect(shape.getPosition().x,shape.getPosition().y,shape.getSize().x,shape.getSize().y);
                if(Keyboard::isKeyPressed(Keyboard::Return))
                {
                        if(firsttap==false)
                        {
                               
                                currentframe++;
                                firsttap=true;
                                rect[currentframe]=selectrect; 
                       
                        }
                }
                else
                {
                        firsttap=false;
                }
               
        window.draw(sprite);
        window.draw(shape);    
        }
        else
        {
                save();
                window.close();
        }
       
}





Crop::save()
{
        Image image[numberOfFrames];
        Vector2i totalsize;


        for(int x=1;x<numberOfFrames+1;x++)
        {
               
                image[x].loadFromFile("frames/"+sframe[x]);
               
               
        }
       
       
       
       
        Image saveimage;

        Vector2i currentsize;
        bool row=true;
        Vector2i sizecheck;
        for(int x=0;x<numberOfFrames;x++)
        {
                if(totalsize.x<1000)
                {
                        totalsize.x+=rect[x].width;
                }
               
                if(sizecheck.x<1000)
                {
                        sizecheck.x+=rect[x].width;
                }
                else
                {
                       
                        totalsize.y+=rect[x].height;
                        sizecheck.x=0; 
                }
               
        }

        saveimage.create(totalsize.x,totalsize.y,Color::Transparent);
       

        for(int x=0;x<numberOfFrames;x++)
        {      
               
                currentsize.x+=rect[x].width;
               

       
                if(currentsize.x<=totalsize.x)
                {
                        //
                        for(int x1=currentsize.x-rect[x].width;x1<currentsize.x;x1++)
                        {
                                for(int y=currentsize.y-rect[x].height;y<currentsize.y;y++)
                                {
                                        saveimage.setPixel(x1,y,image[x].getPixel(x1-currentsize.x,y-currentsize.y));
                                }
                        }      
                }
                else
                {
                        currentsize.y+=rect[x].height;
                        currentsize.x=0;
                }
        }
 
        saveimage.saveToFile("test/sheet.png");
        //WHY DO I KEEP RUNNING INTO THIS PROBLEM WHERE IMAGES DONT SAVE AND SHOW NO ERROR?!
       
}

Ok.So my code is extremely confusing to anyone not familiar with my terms but i'm absolutely certain that the save() function is where the problem is. And it is certain that the images are loaded  into 
Image image[numberOfFrames];
without any problems since these images have been saved as separate files before I tried combining them into one image.The important thing is getting the image called "saveimage" to save to file.

Any ideas what wrong here?

13
Window / ffplay causes sfml window to freeze and crash.
« on: October 19, 2023, 03:11:54 pm »
Just  like the title says"ffplay causes sfml window to freeze and crash".Any ideas how to bypass or fix this problem?

14
Audio / Playing sound causes frame or line skips.
« on: October 15, 2023, 03:58:39 am »
I'm having a problem with a function I made and I was wondering if anyone could help me figure out the problem.I have a file called playsound.h,and a .cpp file for that. When the function runs,a sound plays as wanted but it causes a problem. I'm not sure if it causes a lag or a line skip,or a frame skip or what.All I know is that it causes image skips and it causes the program to get its variables all messed up so I assume it has something to do with skipping some code. So the question is" Why does it do this?".


playsound.h

#pragma once
#include <SFML\Graphics.hpp>
#include <SFML/Audio.hpp>
using namespace sf;
#include <string>
using namespace std;


extern Sound channel[50];
extern SoundBuffer noise[50];
extern string lastsound[50];
void playsound(int channelnumber,string soundDirectory);



playsound.cpp

#include <SFML\Audio.hpp>
using namespace sf;
#include "playsound.h"
#include <string>
using namespace std;

Sound channel[50];
SoundBuffer noise[50];
string lastsound[50];

void playsound(int channelnumber,string soundDirectory)
{

        if(soundDirectory!=lastsound[channelnumber])
        {
                noise[channelnumber].loadFromFile(soundDirectory);
                channel[channelnumber].setBuffer(noise[channelnumber]);

                if(channel[channelnumber].getStatus()!=Sound::Playing)
                {
                        channel[channelnumber].play();
                        lastsound[channelnumber]=soundDirectory;
                }
        }
        if(channel[channelnumber].getStatus()!=Sound::Playing)
        {
                lastsound[channelnumber]="";
        }
}

 


15
General / drawing Text array to screen crashes window.
« on: August 26, 2023, 02:39:42 am »
I'm trying to learn to use sfml's networking to make a chat program.I got this to work in console so I decided to do it with a window and Text. I was planning on having an array of Text that displays the received messages. This is called "mess".Drawing the array to screen using a for loop results in the window crashing.This however doesn't happen for the first index of mess. I tried limiting the for loop to just 0 but this still results in a crash.by the way,the typing input does draw to screen with no problem.

#include <iostream>
#include <SFML\Network.hpp>
#include "main.h"
using namespace std;
#include <SFML\Graphics.hpp>
using namespace sf;






RenderWindow window(VideoMode(960,540),"");


int main()
{
       
       
        int currentline;
        Font font;
        font.loadFromFile("C:\\Windows\\Fonts\\comic.ttf");
        Text typing;
        Text mess[4000];
        for(int x=0;x<4000;x++)
        {
                mess[x].setFont(font);
                mess[x].setCharacterSize(24);
                mess[x].setFillColor(Color::Blue);
        }
        typing.setFont(font);
       
        typing.setCharacterSize(24);
        typing.setFillColor(Color::Blue);

       
        Clock clock;
       
       
       
       
       
       
       
        IpAddress ip=IpAddress::getLocalAddress();
        string text="Connected to:";
        char buffer[2000];
        size_t received;
       
        TcpSocket socket;
        char connectiontype,mode;
        cout<<"Enter(s) for server,Enter (c) for client.\n";
        cin>>connectiontype;

        if(connectiontype==&#39;s&#39;)
        {
                TcpListener listener;
                listener.listen(5300);
                listener.accept(socket);
                text+="Server";
               
               
        }
        else if(connectiontype==&#39;c&#39;)
        {
                socket.connect(ip,5300);
                text +="Client";
                       
        }
        mess[0].setString(text);
        string input;
        while(window.isOpen())
        {
               
               
                        if(Keyboard::isKeyPressed(Keyboard::Return))
                        {
                                string typed=typing.getString();
                                socket.send(&#39;~&#39;+typed.c_str(),typed.length()+1);       
                                typing.setString("");
                                input="";
                        }
                       
                        socket.receive(buffer,sizeof(buffer),received);
                       
                if(buffer[0]==&#39;~&#39;)     
                {
                        mess[currentline].setString(string(buffer));
                        buffer[0]=&#39;&#39;;
                        currentline++;
                }
               
               
               
                Event e;
               
                while(window.pollEvent(e))
                {
                        if(e.type==Event::Closed)
                                window.close();
               
               
               
                        if(e.type==Event::TextEntered)
                        {
                                input+=e.text.unicode;
                               
                                typing.setString(input);
                        }
                }
               
               
               
               
               
                window.clear(Color::Cyan);
               
                window.draw(mess[0]);
                //window.draw(mess[1]);
                for(int x=0;x<currentline;x++)
                {
                        mess[x].setPosition(0,mess[x].getCharacterSize()*currentline);
                        window.draw(mess[x]);
                }
                typing.setPosition(0,mess[0].getCharacterSize()*(currentline+1));      
                window.draw(typing);
               
                window.display();
        }
        return 0;
       
}      

Pages: [1] 2