Как избавится от ошибки?
Код:
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <time.h>
#undef main
int keys(SDL_Event*e,int key)
{
switch(e->key.keysym.sym)
{
case SDLK_ESCAPE:
return 0;
break;
case SDLK_DOWN:
if(key!=4)
{
key++;
}
return key;
break;
case SDLK_UP:
if(key!=1)
{
key--;
}
return key;
break;
case SDLK_RIGHT:
break;
case SDLK_LEFT:
break;
case SDLK_RETURN:
if(key==4)
{
return 0;
}
break;
}
}
void LoadImege(char *path,SDL_Renderer *ren)
{
SDL_Surface *surface=SDL_LoadBMP(path);
SDL_Texture *texture=SDL_CreateTextureFromSurface(ren,surface);
SDL_Rect rect;
rect.h=surface->h;
rect.w=surface->w;
rect.x=0;
rect.y=170;
SDL_RenderCopy(ren,texture,NULL,&rect);
}
void LoadText(SDL_Renderer *ren,char *word,int *x, int *y,TTF_Font *font,int *size_x,int *size_y,int *target)
{
SDL_Color color= {200,100,20},bkcolor={200,150,0};
SDL_Surface *surface;
if(target==1)
{
surface=TTF_RenderText_Shaded(font,word,color,bkcolor);
}
else
{
surface=TTF_RenderText_Blended(font,word,color);
}
SDL_Texture *texture=SDL_CreateTextureFromSurface(ren,surface);
SDL_Rect rect= {x,y,size_x,size_y};
SDL_RenderCopy(ren,texture,NULL,&rect);
}
int main(int arge,char**argv)
{
srand(time(0));
if(SDL_Init(SDL_INIT_VIDEO)<0)
{
puts("video_error");
return 1;
}
if(TTF_Init()<0)
{
puts("text_error");
return 1;
}
TTF_Font *font=TTF_OpenFont("arial.ttf",50);
SDL_Window *win=SDL_CreateWindow("Menu",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,1280,1024,SDL_WINDOW_SHOWN);
SDL_Renderer*ren=SDL_CreateRenderer(win,-1,SDL_RENDERER_SOFTWARE);
SDL_RenderPresent(ren);
int key=1;
int ok=1;
SDL_Event event;
while(ok)
{
LoadImege("fon.bmp",ren);
if(key==1) LoadText(ren,"Punct 1",600,200,font,100,100,1);
else LoadText(ren,"Punct 1",600,200,font,100,100,0);
if(key==2) LoadText(ren,"Punct 2",600,300,font,100,100,1);
else LoadText(ren,"Punct 2",600,300,font,100,100,0);
if(key==3)LoadText(ren,"Punct 3",600,400,font,100,100,1);
else LoadText(ren,"Punct 3",600,400,font,100,100,0);
if(key==4)LoadText(ren,"Punct 4",600,500,font,100,100,1);
else LoadText(ren,"Punct 4",600,500,font,100,100,0);
while(SDL_PollEvent(&event))
{
switch(event.type)
{
break;
case SDL_KEYDOWN:
ok=keys(&event,key);
key=ok;
break;
}
}
SDL_RenderPresent(ren);
SDL_RenderClear(ren);
}
return 0;
}
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <time.h>
#undef main
int keys(SDL_Event*e,int key)
{
switch(e->key.keysym.sym)
{
case SDLK_ESCAPE:
return 0;
break;
case SDLK_DOWN:
if(key!=4)
{
key++;
}
return key;
break;
case SDLK_UP:
if(key!=1)
{
key--;
}
return key;
break;
case SDLK_RIGHT:
break;
case SDLK_LEFT:
break;
case SDLK_RETURN:
if(key==4)
{
return 0;
}
break;
}
}
void LoadImege(char *path,SDL_Renderer *ren)
{
SDL_Surface *surface=SDL_LoadBMP(path);
SDL_Texture *texture=SDL_CreateTextureFromSurface(ren,surface);
SDL_Rect rect;
rect.h=surface->h;
rect.w=surface->w;
rect.x=0;
rect.y=170;
SDL_RenderCopy(ren,texture,NULL,&rect);
}
void LoadText(SDL_Renderer *ren,char *word,int *x, int *y,TTF_Font *font,int *size_x,int *size_y,int *target)
{
SDL_Color color= {200,100,20},bkcolor={200,150,0};
SDL_Surface *surface;
if(target==1)
{
surface=TTF_RenderText_Shaded(font,word,color,bkcolor);
}
else
{
surface=TTF_RenderText_Blended(font,word,color);
}
SDL_Texture *texture=SDL_CreateTextureFromSurface(ren,surface);
SDL_Rect rect= {x,y,size_x,size_y};
SDL_RenderCopy(ren,texture,NULL,&rect);
}
int main(int arge,char**argv)
{
srand(time(0));
if(SDL_Init(SDL_INIT_VIDEO)<0)
{
puts("video_error");
return 1;
}
if(TTF_Init()<0)
{
puts("text_error");
return 1;
}
TTF_Font *font=TTF_OpenFont("arial.ttf",50);
SDL_Window *win=SDL_CreateWindow("Menu",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,1280,1024,SDL_WINDOW_SHOWN);
SDL_Renderer*ren=SDL_CreateRenderer(win,-1,SDL_RENDERER_SOFTWARE);
SDL_RenderPresent(ren);
int key=1;
int ok=1;
SDL_Event event;
while(ok)
{
LoadImege("fon.bmp",ren);
if(key==1) LoadText(ren,"Punct 1",600,200,font,100,100,1);
else LoadText(ren,"Punct 1",600,200,font,100,100,0);
if(key==2) LoadText(ren,"Punct 2",600,300,font,100,100,1);
else LoadText(ren,"Punct 2",600,300,font,100,100,0);
if(key==3)LoadText(ren,"Punct 3",600,400,font,100,100,1);
else LoadText(ren,"Punct 3",600,400,font,100,100,0);
if(key==4)LoadText(ren,"Punct 4",600,500,font,100,100,1);
else LoadText(ren,"Punct 4",600,500,font,100,100,0);
while(SDL_PollEvent(&event))
{
switch(event.type)
{
break;
case SDL_KEYDOWN:
ok=keys(&event,key);
key=ok;
break;
}
}
SDL_RenderPresent(ren);
SDL_RenderClear(ren);
}
return 0;
}
Что-то код ошибки похож на Access Violation. Но такую простыню кода изучать лень. Попробуйте локализовать ошибку.