sdl-2

SDL2 Window not displaying

◇◆丶佛笑我妖孽 提交于 2019-12-20 07:47:55
问题 I'm trying to open a window with SDL2 in visual studio 2015. I've set a .bmp image in my code to display to the screen in a window, but when I run my code the program returns 0 and closes without a window. The .bmp image is in the project folder. How do you display the window? #include <SDL.h> #include <iostream> int main(int argc, char* args[]) { SDL_Window *window = nullptr; SDL_Surface *windowSurface = nullptr; SDL_Surface *imageSurface = nullptr; if (SDL_Init(SDL_INIT_VIDEO) < 0) std:

Linker Errors from SDL2 in my project

不打扰是莪最后的温柔 提交于 2019-12-20 06:39:12
问题 I used CMake and Code::Blocks to build SDL2 from source, and attempted to link my own project source to the following static libraries: libSDL2.a libSDL2main.a OpenGL32.lib These three libraries are contained within the directory known as %libdir% (I'm using Batch for the command). I obtained libSDL2 and libSDL2main from the Code::Blocks build. I obtained OpenGL32 from my Windows directory, although I found it long ago so I am unable to recall the exact location. I used the following command:

SDL_GetTicks() accuracy below the millisecond level

a 夏天 提交于 2019-12-19 21:20:23
问题 I program currently something with SDL2. All works fine, but I have a problem with the SDL_GetTicks() method. Normally it should return the total application time in milliseconds, but it always returns most of the time the value 0 and sometimes the value 1. I initialized SDL with SDL_INIT_EVERYTHING flag. The problem with the following code is the loop is too fast, so the delta time is smaller than 1 ms. Is there a method to achieve a higher precision? #include "Application.hpp" void

SDL_GetTicks() accuracy below the millisecond level

若如初见. 提交于 2019-12-19 21:20:21
问题 I program currently something with SDL2. All works fine, but I have a problem with the SDL_GetTicks() method. Normally it should return the total application time in milliseconds, but it always returns most of the time the value 0 and sometimes the value 1. I initialized SDL with SDL_INIT_EVERYTHING flag. The problem with the following code is the loop is too fast, so the delta time is smaller than 1 ms. Is there a method to achieve a higher precision? #include "Application.hpp" void

Get pixel info from SDL2 texture

可紊 提交于 2019-12-19 10:17:55
问题 I'm currently writing a simple program using SDL2 where you can drag some shapes (square, circle, triangle, etc) into a canvas and rotate them and move them around. Each shape is represented visually by a SDL texture that is created from a PNG file (using the IMG_LoadTexture function from the SDL_image library). The thing is that I would like to know whether a certain pixel from the texture is transparent, so that when someone clicks on the image I could determine if I have to do some action

how many pixels is a meter in Box2D?

假如想象 提交于 2019-12-19 10:10:45
问题 Question is simple so, no codes! If someone knows Box2D and SDL2, then, please tell me how to wrap SDL_Rect with b2body. Ofcourse, it requires to know the conversion of metre to pixel and vice versa. This is because Box2D measures distance in metres. Can you give me a simple expression or function to convert metres(of Box2D) to pixels or pixels to metres(of Box2D)? 回答1: Can you give me a simple expression or function to convert metres(of Box2D) to pixels or pixels to metres(of Box2D)?

Sprites sequence control through DeltaTime

谁说胖子不能爱 提交于 2019-12-18 09:48:31
问题 Previously in my main loop of the game, the time was managed at 60 FPS and the respective Delay for the time delay. The Sprite sequence was animated as follows: <pre> if(++ciclos > 10){ siguienteSprite++; ciclos = 0; } </pre> Given that I am using Smooth Motion with DeltaTime, therefore I have eliminated Delay from the Main Cycle; Making this the sprites cycles of the animation are faster, and not only this, but also the time between each sequence varies. Someone could give me a hand, only

Why do I get bad performance with SDL2 and SDL_RenderCopy inside a double for loop over all pixels?

。_饼干妹妹 提交于 2019-12-18 06:49:57
问题 I am programming a raycasting game using SDL2. When drawing the floor, I need to call SDL_RenderCopy pixelwise. This leads to a bottleneck which drops the framerate below 10 fps. I am looking for performance boosts but can't seem to find some. Here's a rough overview of the performance drop: int main() { while(true) { for(x=0; x<800; x++) { for(y=0; y<600; y++) { SDL_Rect src = { 0, 0, 1, 1 }; SDL_Rect dst = { x, y, 1, 1 }; SDL_RenderCopy(ren, tx, &src, &dst); // this drops the framerate

How can I get the screen resolution using SDL2?

大兔子大兔子 提交于 2019-12-18 06:09:14
问题 I'm using pixel-perfect source images and SDL2 to make a program. When set to fullscreen, I'd like it to use the native resolution (the SDL_WINDOW_FULLSCREEN_DESKTOP flag) but only between a certain minimum resolution and a reasonable maximum one, after which it will stretch from the largest legal resolution. The problem is that I can only find references to the program's own window or program size on the SDL2 documentation. Is there any function in SDL from which I could retrieve the screen

SDL2 C++ Taking a screenshot

心不动则不痛 提交于 2019-12-18 01:15:15
问题 Hi I would like to know if it is possible to simply take a screenshot with SDL2. I tried SDL_GetWindowSurface but I get an error saying: No hardware accelerated renderers available. I took the code from here. Another solution I thought about is converting a texture to a surface but I didn't manage to do so... Do you have any solution? 回答1: It seems like you are mixing the rendering systems. That method will only work in the context of software rendering. For hardware rendering you should use