gpt4 book ai didi

c++ - Visual Studio 2017 空白窗口,无响应

转载 作者:行者123 更新时间:2023-11-30 02:23:58 24 4
gpt4 key购买 nike

我一直在尝试在 Visual Studio 2017 中创建一个简单的 C++ 游戏,但我什至无法获得简单的黑屏。窗口出现白色且无响应,有人可以帮忙吗?我一直在从 Udemy 上的免费类(class)中学习,它一直有效到现在。我的代码如下。

#include <iostream>
#include <SDL.h>
#include <string>
using namespace std;
int main(int argc, char* argv[]) {
const int screenWidth = 800;
const int screenLength = 600;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
cout << "SDL init faliure" << endl;
return 0;

}
SDL_Window *window = SDL_CreateWindow("Particle Fire", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screenWidth, screenLength, SDL_WINDOW_SHOWN);
SDL_Delay(100000);

if (window == NULL) {
SDL_Quit();
return 2;
}
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);
SDL_Texture * texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC, screenWidth, screenLength);

if (renderer == NULL) {
cout << "Could not produce renderer";
SDL_DestroyWindow(window);
SDL_Quit();
return 3;

}
if (texture == NULL) {
cout << "Could not produce texture";
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 3;
}
Uint32 *buffer = new Uint32[screenWidth*screenLength];
memset(buffer, 0xFF, screenWidth*screenLength*sizeof(Uint32));
for (int i=0; i < screenWidth*screenLength; i++) {

buffer[i = 0xFFFF0000];
}
SDL_UpdateTexture(texture, NULL, buffer, screenWidth * sizeof(Uint32));
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
bool quit = false;
SDL_UpdateTexture(texture, NULL, buffer, screenWidth * sizeof(Uint32));
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer,texture , NULL, NULL);
SDL_RenderPresent(renderer);
SDL_Event event;
while (!quit) {

while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
} }

}
delete buffer;
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
}

我试过改变一切,但它不起作用。

最佳答案

在创建窗口 SDL_Delay(100000); 后立即有 100 秒的延迟。

此外,您需要将 buffer[i = 0xFFFF0000] 更改为 buffer[i] = 0xFFFF0000。第一个只设置 i 并保持缓冲区不变。第二个使像素变黄。

关于c++ - Visual Studio 2017 空白窗口,无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45636734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com