sdl

Using SDL_ttf with OpenGL

天涯浪子 提交于 2019-11-26 22:39:37
问题 I'm using OpenGL and SDL to create a window in my program. How do I use SDL_ttf with an OpenGL window? For example I want to load a font and render some text. I want to draw the text using an SDL OpenGL surface. 回答1: Here's how to do it: Initialize SDL and SDL_ttf, and create a window using SDL_SetVideoMode() . Make sure you pass the SDL_OPENGL flag. Initialize your OpenGL scene ( glViewport() , glMatrixMode() etc.). Render your text with SDL_ttf using e.g. TTF_RenderUTF8_Blended() . The

“winapifamily.h: No such file or directory” when compiling SDL in Code::Blocks

為{幸葍}努か 提交于 2019-11-26 22:37:07
问题 I am following along with the SDL2.0 tutorials by LazyFoo, using Code::Blocks 13.12. I have had no trouble getting SDL2 linked and running in VS2010 but have changed IDE and come across this error: winapifamily.h: No such file or directory I think everything is linked correctly. I have pointed the program to my SDL2 include and lib directories. Buildlog: (error is occuring in file: ..\include\SDL2\SDL_platform.h) === Build: Debug in SDL2_Setup (compiler: GNU GCC Compiler) === fatal error:

Drawing 2D stuff with SDL_Renderer and OpenGL stuff with SDL_GLContext

房东的猫 提交于 2019-11-26 22:05:07
问题 I have been learning about SDL 2D programming for a while and now I wanted to create a program using SDL and OpenGL combined. I set it up like this: SDL_Init(SDL_INIT_VIDEO); window = SDL_CreateWindow("SDL and OpenGL", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); context = SDL_GL_CreateContext(window); The program is for now just a black window with a white line displayed using OpenGl. Here is the code for the rendering: glClearColor(0, 0, 0, 0); glClear

OpenGL Scale Single Pixel Line

筅森魡賤 提交于 2019-11-26 21:10:23
I would like to make a game that is internally 320x240, but renders to the screen at whole number multiples of this (640x480, 960,720, etc). I am going for retro 2D pixel graphics. I have achieved this by setting the internal resolution via glOrtho(): glOrtho(0, 320, 240, 0, 0, 1); And then I scale up the output resolution by a factor of 3, like this: glViewport(0,0,960,720); window = SDL_CreateWindow("Title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 960, 720, SDL_WINDOW_OPENGL); I draw rectangles like this: glBegin(GL_LINE_LOOP); glVertex2f(rect_x, rect_y); glVertex2f(rect_x + rect_w,

Smart pointers with SDL

我的未来我决定 提交于 2019-11-26 19:54:43
问题 For my game should I use a raw pointer to create SDL_Window , SDL_Renderer , SDL_Texture etc. as they have specific delete functions SDL_DestroyTexture(texture); or should I add a custom deleter when I create a unique_ptr or shared_ptr and if so how would I do this with SDL types? 回答1: You could create a functor that has several overloaded operator() implementations, each of which call the correct destroy function for the respective argument type. struct sdl_deleter { void operator()(SDL

Why does valgrind say basic SDL program is leaking memory?

自闭症网瘾萝莉.ら 提交于 2019-11-26 18:18:17
问题 Here is the SDL program: #include <SDL/SDL.h> int main(int argc, char** argv){ SDL_Init(SDL_INIT_VIDEO); SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE); SDL_Quit(); return 0; } Compiled with the command: g++ -o test test.cpp -lSDL And here is the output of valgrind: christian@christian-laptop:~/cpp/tetris$ valgrind --leak-check=full ./test ==3271== Memcheck, a memory error detector ==3271== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==3271== Using

Mingw+SDL移植须知:不要尝试在Windows上用线程解析事件!

℡╲_俬逩灬. 提交于 2019-11-26 17:18:06
欢迎访问 http://omegacoleman.sinaapp.com/ =========== 最近在弄SDL,在Linux(fc17)下完成开发后,准备用mingw移植到Windows平台。相比在Windows下用mingw编译,其实有更好的方案:在Linux上直接使用mingw交叉编译,方法如下: -没安装mingw32-gcc的,用包管理器安装。我这里是: yum install mingw32-gcc -然后,运行i686-w64-mingw32-gcc,就像在运行gcc一样进行编译。使用SDL时建议加上 -lmingw32,最后,命令应该是这样: i686-w64-mingw32-gcc ….c -o ….exe -lSDL -lSDL_image -lSDL_gfx -lmingw32 … -Wall 这个时候第一个问题出现了:gcc正确编译的代码被报错了: /usr/i686-w64-mingw32/sys-root/mingw/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o): (.text.startup+0x39): undefined reference to `WinMain@16' collect2: error: ld returned 1 exit status google之后,有了答案

libpng warning: iCCP: known incorrect sRGB profile

↘锁芯ラ 提交于 2019-11-26 17:01:38
I'm trying to load a PNG image using SDL but the program doesn't work and this error appears in the console libpng warning: iCCP: known incorrect sRGB profile Why does this warning appear? What should I do to solve this problem? Glenn Randers-Pehrson Libpng-1.6 is more stringent about checking ICC profiles than previous versions. You can ignore the warning. To get rid of it, remove the iCCP chunk from the PNG image. Some applications treat warnings as errors; if you are using such an application you do have to remove the chunk. You can do that with any of a variety of PNG editors such as

SDL_PollEvent() stuttering while idle?

不羁岁月 提交于 2019-11-26 16:37:31
问题 I've cobbled together a very basic game loop in C++ using SDL2, and I've noticed that every few seconds, SDL_PollEvent seems to be unusually slow, even when nothing is happening. I sent my deltaTime to console every loop, and its about 100ms difference on the cycles that SDL_PollEvent is lagging. I've already confirmed that it's something with this function by moving my timers around, but I'm not sure where to diagnose the issue further. My loop: while (!quit) { uint32_t startTime = SDL

Difference between surface and texture (SDL / general)

 ̄綄美尐妖づ 提交于 2019-11-26 15:22:50
问题 Can anyone explain to me in simple words what is the difference between texture and surface? I saw it used in SDL2 as SDL_Surface and SDL_Texture . SDL_Texture is created from SDL_Surface which in turn is created from image/bitmap. Both are collection of pixels. But I do not see the main difference between them (has to do something with GPU?) I tried to google it but all explanations I found were too complex to understand them without digging deeper into computer graphics stuff. 回答1: