sdl

Getting smooth, big points in OpenGL

匿名 (未验证) 提交于 2019-12-03 01:06:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I started playing around with OpenGL and GLUT. I would like to draw some points, but the problem is that they turn out to be squares, and I would like them to be round dots (filled circles). This is what I do: void onInitialization ( ) { glEnable ( GL_POINT_SMOOTH ); glEnable ( GL_BLEND ); glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ); glPointSize ( 6.0 ); } void onDisplay () { glClearColor ( 1.0f , 1.0f , 1.0f , 1.0f ); glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glBegin ( GL_POINTS ); glColor3f ( 0.95f , 0.207

Undefined reference to 'SDL_main'

匿名 (未验证) 提交于 2019-12-03 00:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I've recently decided to try working with SDL with CodeBlocks 10.05. I started with the tutorial on http://www.sdltutorials.com/sdl-tutorial-basics and did my best to follow it. Unfortunately, I'm encountering: .. \. . \. . \. . \. . \. . \SDL\SDL - 1.2 . 15 \lib\libSDLmain . a ( SDL_win32_main . o ): SDL_win32_main . c || undefined reference to `SDL_main'| when I try to compile it. I've searched through many of the questions on this website and other tutorials (mainly the tutorial on LazyFoo and the CodeBlocks wiki) and can't seem

OpenGL Low-Level Performance Questions

Deadly 提交于 2019-12-02 21:35:31
This subject, as with any optimisation problem, gets hit on a lot, but I just couldn't find what I (think) I want. A lot of tutorials, and even SO questions have similar tips; generally covering: Use GL face culling (the OpenGL function, not the scene logic) Only send 1 matrix to the GPU (projectionModelView combination), therefore decreasing the MVP calculations from per vertex to once per model (as it should be). Use interleaved Vertices Minimize as many GL calls as possible, batch where appropriate And possibly a few/many others. I am (for curiosity reasons) rendering 28 million triangles

SDL - drawing 'negative' circles (Fog of War)

删除回忆录丶 提交于 2019-12-02 21:14:12
I have this 800x600square I want to draw to the screen. I want to 'cut' circles in it (where alpha would be 0). Basically I'm drawing this whole rectangle over a map so in these 'circles' I drew, you can see the map, otherwise you see the grey square So, I assume you're trying to add fog of war to one of you game? I had a small demo I made for a local University a few weeks ago to show A* pathfinding, so I thought I could add fog of war to it for you. Here's the results: Initial map First, you start with a complete map, totally visible Fog Then, I added a surface to cover the entire screen

c++ integer division

旧巷老猫 提交于 2019-12-02 20:54:13
问题 Say I've got SDL_Rect rect; rect.x = 5; // rect.x is of type "Uint16" int y = 11; and I want to perform the operation rect.x/y . I want to get the result as a floating point number and then round up to the nearest int . Something like this: float result = rect.x/y; int rounded = ceil(result); How should I do this? 回答1: Cast either rect.x or y to float, and then do the division. This will force the entire division operation to take place in floating point. float result = rect.x/(float)y; int

SDL embed image inside program executable

只愿长相守 提交于 2019-12-02 19:35:35
Is it possible to embed an image within a program using SDL which can be used at run time. For example, I have a program which brings up a splash screen on startup containing the logo and copyright information. Rather than having this image in a bitmap file and using SDL_LoadBMP to load it to a SDL_Surface. I would like to have the image embedded in the program binary, to stop someone potentially changing the splash image and copyright name. Does anyone have any suggestions on ways to do this? Example code would be great. Embedding a file in an executable is easy but there are some gotchas,

SDL_PollEvent vs SDL_WaitEvent

左心房为你撑大大i 提交于 2019-12-02 19:08:02
So I was reading this article which contains 'Tips and Advice for Multithreaded Programming in SDL' - https://vilimpoc.org/research/portmonitorg/sdl-tips-and-tricks.html It talks about SDL_PollEvent being inefficient as it can cause excessive CPU usage and so recommends using SDL_WaitEvent instead. It shows an example of both loops but I can't see how this would work with a game loop. Is it the case that SDL_WaitEvent should only be used by things which don't require constant updates ie if you had a game running you would perform game logic each frame. The only things I can think it could be

SDL_KEYDOWN and key recognition not working properly

会有一股神秘感。 提交于 2019-12-02 18:15:50
问题 In my project I am having trouble getting a simple switch statement to work for SDL input. Here is the example: SDL_Event event; SDL_PollEvent(&event); if (event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_a: m_x -= 30; break; case SDLK_d: m_x += 30; break; case SDLK_w: m_y -= 30; break; case SDLK_s: m_y += 30; break; } } When I run this, first off it seems SDL_KEYDOWN isn't being recognized. Nor are my cases. So I switched the code to: SDL_Event event; SDL_PollEvent(

Way to increment objects inside an array for 2 hit detection c+

丶灬走出姿态 提交于 2019-12-02 13:41:50
Im creating a basic game using SDL/C++. I need a way to implement 2 hit detection. When just trying one hit it works fine. Here is what i have for the two hit detection: int maxHit = 2; int hitCount = 0; // Detect collisions for(auto p : projectiles) { for(auto a : aliens) { if(p->CollidesWith(a) && hitCount == maxHit) { p->HandleCollision(); a->HandleCollision(); } if(p->CollidesWith(a) && hitCount != maxHit) { ++hitCount; } } } For some reason it works on a select few of the enemies on the screen and doesn't for others. EDITED TO MAKE IT CLEARER Yes, this identifies the object on which the

Strange segfault from SDL_FreeSurface

有些话、适合烂在心里 提交于 2019-12-02 13:38:19
问题 I have the following simple SDL code: #include <SDL.h> #include <stdbool.h> #include <stdio.h> // helpers bool init(SDL_Window **win, SDL_Surface **surf) { int const width = 800; int const height = 600; if (SDL_Init(SDL_INIT_VIDEO) != 0) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); return false; } *win = SDL_CreateWindow("Picture test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, 0); if (*win == NULL) { fprintf(stderr, "Unable to create window: %s\n", SDL