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

Pages: 1 ... 15 16 [17] 18 19 ... 22
241
Graphics / Re: Rendering quads show nothing if texture is ussed
« on: September 13, 2021, 07:35:16 pm »
One potential issue, the UV coordinates for a vertex aren't in pixels, they are 0-1 for full width and height. Higher is wrap around (which may not be enabled, I can't remember the default).
So for example {32.f, 16.f} should be {1.f, 1.f} (the texture isn't square, so 1,1 means full width (32 pixels) and full height (16 pixels)).

242
General discussions / Re: How do i use SFML with microsoft live share?
« on: September 12, 2021, 06:53:22 am »
When you debug in live share, the program is only executed on the host. Other people in the share can look at the source code and access the debugger, but they don't have a local copy running.
If you want other people to see what the program is displaying, you'll need to use a screen share program like Zoom or Discord.

243
Graphics / Re: SF::Text not properly rendering
« on: September 01, 2021, 05:50:10 am »
The Get_Font_By_Name function returns a reference to a Font. But it only contains a return for the font found path, if a font wasn't found there's no return, meaning it is returning an invalid reference.
But that's a separate issue (assuming you don't ask for a font with the wrong name).

The main problem appears to be ThisFont in _LoadFonts. The header comments for sfml's loadFromMemory say that the buffer must remain valid for the life of the font (so sounds like it doesn't copy the data, just uses it). But ThisFont is temporary, it is deleted when it goes out of scope after each font in the loop.
You'll need to store the data you get back from the database in something more persistent, copy it into a block of heap memory and store the pointer and size of that block in the Font_t struct as well.

244
That image doesn't have transparency, the white/grey grid is actually part of it.

245
Graphics / Re: Image with out of objects sf::Texture and sf::Sprite
« on: August 20, 2021, 08:10:52 pm »
Hello! I want to draw an image on user's screen, but I don't want to create objects sf::Texture and sf::Sprite for it because with these method I need a lot of textures and sprites. I want to do it like:
window.draw(sf::Image(x, y, way));
It sounds to me like maybe you mean progressively drawing onto the screen, like a painting program (hence the lots of sprites). If that's the case, have a look at render textures.
A render texture is created in code and can act like a window, you draw sprites into it. But whatever you draw into it will be preserved as part of the texture. You can then draw the render texture into a window just like a normal texture. Good for things like leaving trails, user controlled drawing, etc.
https://www.sfml-dev.org/tutorials/2.5/graphics-draw.php#off-screen-drawing

246
General / Re: Visual studio project broken in release mode
« on: August 19, 2021, 05:22:46 pm »
It applies generally to all C++ programs, not just SFML. Visual Studio has a few differences between debug and release (I'm not as familiar with G++/Clang behavior). The biggest one, as eXpl0it3r mentioned is the uninitialised variable issue.
In debug builds, Visual Studio fills variables with special values. Stack variables are filled with 0xcc. Heap memory is filled with 0xcd. When freed, heap memory is filled with 0xdd. A guard region of 0xfd is placed around allocations to detect overflow.
(A quick test with Clang in VS shows it uses 0xcc for uninitialised variables in debug too)

If your code has (as local variables):
float f;
int i;
then in debug they will have the default values: f = -107374176.0 and i = -858993460. That's how a float and an int interpret the value 0xcccccccc (meaning 4 bytes of uninitialised stack memory).
A bool that's uninitialised will always be true (it will have 0xcc or 0xcd internally, and any non zero value is true).

But all this filling has a performance hit, so in release mode it just leaves whatever is already there, so you may have random values each time it's run. So for example an uninitialised bool that's always started as true in debug will randomly be true or false in release.

247
General / Re: Ant simulation project not working
« on: August 19, 2021, 12:18:36 pm »
I had a quick run of the code, but have been busy with work so haven't gotten it working as I'm guessing it should.
But a few quick notes:
- The general accumulation looks right, force into acceleration, acceleration into velocity, velocity into position. But then position is added to sprite position, so position is acting like another velocity. I'd leave out the GetPosition+position part and set the sprite to just position (giving position the actual sprite pos at the start), or add velocity to GetPosition.
- The velocity starts off small, then quickly converges on microscopic. After a few seconds of running it had values like 0.04, those are in pixels per second, so it would take 25 seconds to move a pixel. It's enough to turn the ant, but not enough to move.
- The reason it drifts is the position variable has velocity added a few times while velocity is big, then as velocity shrinks it has less effect on position and can't overcome the values gathered from the initial few frames. Then position is added to sprite GetPosition, which moves it by that much.
- maxSpeed of 0.5 means 2 seconds to move a pixel.

I think the velocity is going very small because the wandering is a bit too random. Too many large random direction changes will average out.

248
Graphics / Re: Exception produced at 0x0707...((sfml-graphics-d-2.dll)
« on: August 01, 2021, 05:57:12 am »
In the top pic, the "this" pointer is 0. That means updateBoundsCollision is being called on a Player that doesn't exist, it's a null pointer.
You'll need to go back through the call stack (I think it's the "pila de llamadas" tab in the bottom right area) to find where updateBoundsCollision was called from, and why the player was 0.

249
1920x1080 images as 32bit colour take 8.1MB each. The file type and compression have no effect, they must be fully decompressed to raw in memory before the graphics card can understand them.


250
What kinds of resolutions are the 684 images?
A 1024x1024 32 bit colour image takes 4MB of ram.
Resources loaded by LoadResource() remain in ram until the module they came from (in this case the main program) is unloaded, so there's 2 copies of every texture (one as a windows resource and one as an sfml texture).
If we assume 1024x1024 textures, that's 4MB * 684 * 2. That's 5.7GB of ram. 32bit programs on windows only have access to 2GB of ram by default (not 4GB, it reserves have the space for the OS), so you'd run out of ram. You can boost this to around 3.5GB by setting the LARGEADDRESSAWARE flag when compiling or using a tool to set it on an existing program, but that's still not enough.

https://docs.microsoft.com/en-us/cpp/build/reference/largeaddressaware-handle-large-addresses?view=msvc-160

251
Have a look at "spherical coordinates". For example: https://mathinsight.org/spherical_coordinates
From there, the formulas would be:
(phi is vertical angle of kick, theta is horizontal angle of kick, rho is strength of kick)
x = rho * sin(phi) * cos(theta)
y = rho * sin(phi) * sin(theta)
z = rho * cos(theta)

252
General / Re: Unable to reference position in differen't script
« on: July 21, 2021, 02:57:16 pm »
Ok, Albert contains a Ball member.
Does the main game contain a ball too, or is it directly accessing Albert's ball?

If the game has a ball, then the issue is that the game's ball is the one that's updating and Albert's ball isn't updated. There's two balls, one is moving and rendering and the other (not rendered or updated) is the one Albert is watching.

The easiest way to handle that case would be to change Albert's ball to a ball pointer:
Ball *ball;
Then get the game to set that pointer to the address of the game's ball.
//Something like:
albert.ball = &mainBall;
You'll also need to change all of Albert's code that accesses the ball from ball. to ball-> as it's now a pointer.

Here's an example of what I mean (not working code, just an outline):
// Ball.h
class Ball
{
   // Stuff
};

// Albert.h
class Albert
{
   // Stuff
   Ball *ball;
public:
   void setBall(Ball *b) { ball = b; }
};

//main.cpp
#include "Ball.h"
#include "Albert.h"

int main()
{
   Ball mainBall;
   Albert albert;
   albert.setBall(&mainBall);

   // Do all the game stuff

   return 0;
}
 

253
General / Re: Unable to reference position in differen't script
« on: July 20, 2021, 02:53:04 am »
Without being able to see the class declarations I'm just guessing here, but it looks like there might be more than one ball.
Albert has a ball member which isn't a pointer, it looks like it might be a duplicate of the ball from the main game code. So the main ball is being moved around, but Albert is looking at a duplicate that isn't updated.

254
Graphics / Re: how to set background.
« on: July 14, 2021, 03:52:33 am »
setTexture() doesn't take a pointer. It's prototype is:
void setTexture(const Texture& texture, bool resetRect = false);
The texture parameter is a reference. Doing sprite.setTexture(&texture); would be a compile error.


255
General / Re: Reason: Unable to open file
« on: July 04, 2021, 03:59:42 pm »
The default working directory for Visual Studio is $(ProjectDir), which is the directory where the .vcxproj file is located.
The setting for this is in the project properties under Debugging / Working Directory.

Common ones you can include in the setting:
$(ProjectDir) - Where the .vcxproj file is.
$(SolutionDir) - Where the .sln file is.
$(TargetDir) - Where the .exe is put during a build.
(Note: all of these expand to an absolute path with a slash on the end)

I tend to do all of my settings (intermediate, output, etc) relative to the .sln. So I use: $(SolutionDir)bin\
But $(TargetDir) would work too.

Pages: 1 ... 15 16 [17] 18 19 ... 22