Tag: sdl

无效的渲染器SDL2

我正在查看代码,我无法找到无效渲染器问题的解决方案。 我是SDL2的初学者,我必须用纯C编写代码。我认为在我的代码中有更多的错误,但由于这个我不能进一步。 代码是波兰语的一半,所以如果你不能得到我可以重写这一点的地方。 在主要我尝试加载function“Odczyt_z_Pliku”时出现问题。 可能某个地方存在问题。 SDL_GetError()表示“无效的渲染器。 #include #include #include #pragma warning(disable : 4996) #define WYSOKOSC_EKRANU 768 #define SZEROKOSC_EKRANU 1024 typedef enum bool{ false,true }bool; typedef struct sTekstura { int wysokosc; int szerokosc; SDL_Texture *Tekstura; }sTekstura; void IniTekstury(sTekstura T) { T.wysokosc = 0; T.szerokosc = 0; T.Tekstura = NULL; } void free(sTekstura T) { //Free texture […]

SDL保存窗口为BMP

我正在用SDL和C编写程序,我希望能够将窗口保存为图像。 这是我的代码: screen = SDL_GetWindowSurface(win); SDL_SaveBMP(screen,”screen”); 但是当我执行它时,我得到: Segmentation Fault 从其他来源我收集它的指针和内存访问。 有帮助吗?

SDL_SaveBMP将图像上下颠倒

我已经使用SDL通过SDL_SaveBMP保存窗口图像。 问题是保存的图像是颠倒的。 保存的图像是 虽然必须如此 我该如何修复代码? screen_shotfunction: void screen_shot(std::string filename) { int width = glutGet(GLUT_WINDOW_WIDTH); int height = glutGet(GLUT_WINDOW_HEIGHT); SDL_Surface * image = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0); glReadBuffer(GL_FRONT); glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, image->pixels); SDL_SaveBMP(image, filename.c_str()); SDL_FreeSurface(image); } 更新 我尝试翻转像素。 结果是纯黑色输出图像。 问题是什么? #include “SDL/SDL.h” #include “SDL/SDL_image.h” #include #include #include #include #include […]

SDL_GetKeyboardState无法正常工作

我正在尝试为SDL 2的游戏制作一个控制器(不想在gamedev上询问,因为它不是直接的游戏问题)我使用SDL_GetKeyboardEvent来查看导航箭头是否被按下但是它显然不起作用,如果按下其中一个键,它应该打印一个值1或-1但它不会打印0即使我按住键几秒钟,它就像它没有检测到键被压了。 我搜索了整个互联网,这就是他们如何做到的,但它对我不起作用。 #define SDL_MAIN_HANDLED #include #include “SDL.h” /* I’ll add some code later so something that isn’t used might be initialized */ int main (void) { int a = 1; int x; int z; SDL_Event quit; const Uint8 *keys = SDL_GetKeyboardState(NULL); SDL_Init(SDL_INIT_VIDEO); while(a) { SDL_PollEvent(&quit); if(quit.type == SDL_QUIT) a = 0; if(keys[SDL_SCANCODE_UP]) z = […]

C调用链表内容的函数

我正在使用GLib来管理链表。 我正在声明2个结构并将它们放在一个链表中,如下所示。 Asteroid asteroid = {0,0,50,50,50} Asteroid asteroids = {0,0,200,200,50}; GList *asteroidList = NULL; asteroidList = g_list_append(asteroidList, &asteroid); asteroidList = g_list_append(asteroidList, &asteroids); 然后我使用以下函数遍历列表和calla函数,将结构绘制为屏幕,如下所示 void drawAsteroids(){ GList *list = asteroidList; while(list != NULL){ printf(“Asteroids”); GList *next = list->next; drawAsteroid(list->data); list = next; } } 绘图function是 void drawAsteroid(void *asteroid){ Asteroid *newAsteroid = (Asteroid *)asteroid; printf(“%d\n”, newAsteroid->xPos); circleRGBA(renderer, […]

康威的生命游戏:更改邻居计数function后,单元格更改计算错误

想知道是否有人可以帮助我解决这个小问题。 我写了一个函数来计算康威生命游戏中一个细胞的活着的邻居: int countLivingNeighbours(int a[][GRID_WIDTH], int x, int y){ int count = 0, cx, cy; for(cy = y – 1; cy <= y + 1; cy++){ for(cx = x – 1; cx <= x + 1; cx++){ if(a[cy][cx] == ALIVE){ count++; } } } // subtract 1 so it's not counting it's own cell count–; […]

包含SDL时,简单的tcp echo程序无法正常工作?

我有这个奇怪的问题,每当我#include “SDL/SDL.h” ,我的Windows套接字程序都不会执行。 它可以编译但运行时不会执行任何操作。 当我删除#include “SDL/SDL.h”标头,编译并运行时,它又开始工作了吗? 我正在尝试使SDL和我的原始套接字程序工作,但我不明白这是错误的。 //#include “SDL/SDL.h” #define _WIN32_WINNT 0x501 #include #include #include #include #include #include #define MAXLEN 80 using namespace std; const int winsockVersion = 2; int main( int argc, char* args[] ) { WSADATA wsadata; if ( (WSAStartup(MAKEWORD(2,0),&wsadata)) == 0){ cout<<"-[ WSAStartup Initialized. ]" << endl; char PORT[MAXLEN]; char SERVER[MAXLEN]; cout […]

来自SDL_FreeSurface的奇怪段错误

我有以下简单的SDL代码: #include #include #include // 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 […]

SDL2 OSX上的SDL_GetWindowSurface和/或SDL_CreateRenderer上的渲染器无效

所以我一直在玩SDL2以确定它是否符合我的需求。 我正在按照介绍性示例(主要来自lazyfoo)进行简单的测试。 #include #include const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; int main(int argc, char const *argv[]) { /* The window handle */ SDL_Window* window = NULL; /* The surface contained in the window */ SDL_Surface* screen_surface = NULL; /* Init SDL */ if(SDL_Init(SDL_INIT_VIDEO) format, 0x50, 0x50, 0x50)); // /* Update the […]

HarfBuzz – hb_shape()会导致访问冲突

基于此示例 ,我尝试在SDL应用程序中实现字体呈现。 调用hb_shape()时 ,应用程序因访问冲突而暂停。 DLL-download-link(win32): 这里 {harfbuzz-0.9.26-win32.zip} ErrorMsg(VC2012):ConsoleApplication2.exe中0x6160B7F0(libharfbuzz-0.dll)处的未处理exception:0xC0000005:读取位置0x00000068时发生访问冲突 编辑:为简单起见,我将示例更改为控制台应用程序。 Edit2:现在静态链接,用VC ++的LIB.exe创建.lib文件。 #include #include #include #include #pragma comment(lib,”lib/x86/freetype253ST.lib”) // freetype single-thread #pragma comment (lib,”libharfbuzz-0.lib”) // linked to libharfbuzz.dll, created by LIB.exe int main() { hb_font_t* font = NULL; hb_buffer_t* buffer = NULL; FT_Library flib; FT_Face face; bool found = false; const char text[] = {“Write something….”}; […]