gpt4 book ai didi

c++ - 进程返回 255 (0xff) 个代码块

转载 作者:行者123 更新时间:2023-11-28 06:17:40 25 4
gpt4 key购买 nike

<分区>

我不知道我的问题出在哪里。我试着编译一次代码,它成功了。但是,我将它复制到一个新项目中以修改它,只是颜色或等待时间,它只适用于第一个程序。怎么了?我真的很沮丧。使用此代码,我想绘制正弦函数的图形。这是我的代码:

#include <stdio.h>
# include <SDL.h>
# include <math.h>
# define PI 3.141592
# define SCREEN_WIDTH 640
# define SCREEN_HEIGHT 480

int main(int argc, char **argv){

int x,y;

double fx,angulo;

// Uint8* posicion;

Uint32 color;

SDL_Window*win = SDL_CreateWindow("y=sin(x)", 100,100, 640, 480, 0);


// SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION,"info", "Window creada",win);

SDL_Renderer*ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

/* Create surface */

SDL_Surface*surface = SDL_CreateRGBSurface(0,SCREEN_WIDTH,SCREEN_HEIGHT,0,32,0,0,0);


//get the pixels

Uint32*pixels = (Uint32*)surface-> pixels;


/* Lock the surface */

SDL_LockSurface(surface);


color = SDL_MapRGB(surface-> format, 255, 0, 0);

for(x=0;x<360;x++){

angulo=x*PI/180;

fx=240+50*sin(angulo);

y=round(fx);

pixels[ ( y* surface-> w ) + x ] = color;

}

/* Unlock the surface */

SDL_UnlockSurface(surface);


//imprescindible

SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, surface);

SDL_RenderCopy(ren,tex,NULL,NULL);

SDL_RenderPresent(ren);

SDL_Delay(1000);

return 0;

}

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