本文整理汇总了C++中SDL_RenderPresent函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_RenderPresent函数的具体用法?C++ SDL_RenderPresent怎么用?C++ SDL_RenderPresent使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_RenderPresent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SDL_RenderPresent
void ModoGraficoSDL::actualizar()
{
SDL_RenderPresent(this->renderizador);
}
示例2: main
int main(int argc, const char *argv[])
{
if(argc != 2) {
printf("%s takes .ttf file as argument.\n", argv[0]);
return 1;
}
SDL_version compile_version;
const SDL_version *link_version=TTF_Linked_Version();
SDL_TTF_VERSION(&compile_version);
printf("compiled with SDL_ttf version: %d.%d.%d\n",
compile_version.major,
compile_version.minor,
compile_version.patch);
printf("running with SDL_ttf version: %d.%d.%d\n",
link_version->major,
link_version->minor,
link_version->patch);
if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
printf("Error with import!\n");
return 1;
}
SDL_Window *win = SDL_CreateWindow( "TTF Test",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800,
600,
SDL_WINDOW_SHOWN);
SDL_Renderer *renderer = SDL_CreateRenderer(win,
-1,
SDL_RENDERER_ACCELERATED |
SDL_RENDERER_PRESENTVSYNC);
if(TTF_Init() == -1) {
printf("Error loading TTF_Init()!\n%s\n", TTF_GetError());
SDL_Quit();
exit(2);
}
TTF_Font *font;
/* MS Himalaya (himalaya.ttf): http://fontzone.net/font-details/microsoft-himalaya */
font = TTF_OpenFont(argv[1], 600);
if(!font) {
printf("%s\n", TTF_GetError());
return 1;
}
const char tibstring[] = { 0xe0, 0xbd, 0x96,
0xe0, 0xbd, 0xa6,
0xe0, 0xbe, 0x90,
0xe0, 0xbe, 0xb1,
0xe0, 0xbd, 0xbc,
0xe0, 0xbd, 0x84,
0xe0, 0xbd, 0xa6 };
SDL_Color colour = { 255, 255, 255, 255 };
SDL_Surface *surface = TTF_RenderUTF8_Solid(font, tibstring, colour);
if(surface == NULL) {
TTF_CloseFont(font);
printf("Surface error!\n");
return 0;
}
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_Event event;
int quit = 0;
while (!quit) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT)
quit = 1;
}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
TTF_CloseFont(font);
SDL_Quit();
return 0;
}
示例3: main
int main(int argc, char *args[]) {
SDL_Init(SDL_INIT_EVERYTHING); //Init SDL
Mix_Init(MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG); //Init SDL Mixer
Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 4096); //Open audiostream
int temp = officalDelay; //The delay it will play
int holder = -1; //Hold which sound it played before
int counter = 0; //How many soundclips have been played
//Create window and check if it's loaded
SDL_Window *win = SDL_CreateWindow("Omvand Synestesi", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 800, SDL_WINDOW_SHOWN);
if (win == NULL) {
std::cout << "Couldn't create window, unkown error." << std::endl;
}
//Make a renderer
SDL_Renderer *renderer = SDL_CreateRenderer(win, 0, SDL_RENDERER_ACCELERATED);
//Create a texture, load it. Check if it's loaded
SDL_Texture *texture = load_texture("get.bmp", renderer);
if(texture == NULL) {
std::cout << "Couldn't load picture, check so it's named get.bmp" << std::endl;
}
//Loads a surface, this is the picture it will take and make sound of.
SDL_Surface *image = SDL_LoadBMP("get.bmp");
if (image == NULL) {
std::cout << "Couldn't load picture until surface. Check the name so it is get.bmp" << std::endl;
}
//Load soundfiles
Mix_Music *sound[15];
for (int i = 1; i < 16; i++) {
std::string path = "sound/get" + convertInt(i) + ".wav";
sound[i] = Mix_LoadMUS(path.c_str());
std::cout << "Loaded soundfile: " << path << std::endl;
if (sound[i] == NULL) {
std::cout << "Couldn't load soundfile " << path << ". Check so the name is get" << i << ".wav" << std::endl;
}
}
//Loop through the whole picture
for (int y = 0; y < size_h; y++) {
for (int x = 0; x < size_w; x++) {
Uint32 pix = getPixel(image, x, y);
SDL_RenderClear(renderer); //Clear the screen
SDL_RenderCopy(renderer, texture, NULL, NULL); //Print out the picture
SDL_RenderPresent(renderer); //Actually render the picture
int npix = pix % 16 + 1; //Get's a value from the pixel and makes it so it's just 1 to 16
std::cout << "!-- " << pix << " --! " << npix << " | " << counter << "/1296" << std::endl; //Prints out some stuff so you can see for debugging mostly
//If the same value is again, make a longer delay before playing next song, and if not, go back to standard delay
if (npix == holder) {
temp = temp + 120;
}
else {
temp = officalDelay;
}
//Play right soundfile from value of pixel
for (int i = 1; i < 15; i++) {
int newi = i + 1;
if (i == npix) {
Mix_PlayMusic(sound[newi], 0);
SDL_Delay(temp);
holder = i;
}
}
//If value is 16, don't play a sound and make a 3sec long delay.
if (npix == 16) {
std::cout << std::endl << "-----" << std::endl << std::endl;
SDL_Delay(3000);
}
counter++;
}
}
SDL_FreeSurface(image);
SDL_DestroyRenderer(renderer);
SDL_DestroyTexture(texture);
SDL_DestroyWindow(win);
for (int i = 1; i < 16; i++) {
Mix_FreeMusic(sound[i]);
}
Mix_Quit();
SDL_Quit();
return 0;
}
示例4: SDL_RenderCopy
void Window::renderUI() {
SDL_RenderCopy(renderer, textures[UI], NULL, &dstRects[UI]);
SDL_RenderPresent(renderer);
}
示例5: SDL_RenderPresent
void Graphics::flip() {
SDL_RenderPresent(this->_renderer);
}
示例6: SDL_SetRenderDrawColor
void Game::render()
{
SDL_SetRenderDrawColor(_renderer, r, g, b, 0);
SDL_RenderClear(_renderer);
SDL_RenderPresent(_renderer);
}
示例7: while
int Application::exec()
{
bool done = false;
while (!done)
{
SDL_Event e;
if (SDL_WaitEvent(&e))
{
switch (e.type)
{
case SDL_WINDOWEVENT:
{
Widget *w = widgetByWindowId(e.window.windowID);
switch (e.window.event)
{
case SDL_WINDOWEVENT_SHOWN:
std::cout << "Window " << e.window.windowID << " shown" << std::endl;
break;
case SDL_WINDOWEVENT_HIDDEN:
std::cout << "Window " << e.window.windowID << " hidden" << std::endl;
break;
case SDL_WINDOWEVENT_EXPOSED:
{
needUpdateWithoutRedraw_ = w;
break;
}
case SDL_WINDOWEVENT_MOVED:
break;
case SDL_WINDOWEVENT_RESIZED:
{
w->resize(e.window.data1, e.window.data2);
#if __APPLE__==1
SDL_RenderPresent(w->renderer_); // hack for MacOS X
#endif
break;
}
case SDL_WINDOWEVENT_MINIMIZED:
std::cout << "Window " << e.window.windowID << " minimized" << std::endl;
break;
case SDL_WINDOWEVENT_MAXIMIZED:
std::cout << "Window " << e.window.windowID << " maximized" << std::endl;
break;
case SDL_WINDOWEVENT_RESTORED:
std::cout << "Window " << e.window.windowID << " restored" << std::endl;
break;
case SDL_WINDOWEVENT_ENTER:
std::cout << "Mouse entered window " << e.window.windowID << std::endl;
break;
case SDL_WINDOWEVENT_LEAVE:
std::cout << "Mouse left window " << e.window.windowID << std::endl;
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
std::cout << "Window " << e.window.windowID << " gained keyboard focus" << std::endl;
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
std::cout << "Window " << e.window.windowID << " lost keyboard focus" << std::endl;
break;
case SDL_WINDOWEVENT_CLOSE:
std::cout << "Window " << e.window.windowID << " closed" << std::endl;
break;
default:
std::cout << "Window " << e.window.windowID << " got unknown event " << static_cast<int>(e.window.event) << std::endl;
break;
}
break;
}
case SDL_KEYDOWN:
{
KeyEvent ke { static_cast<KeyEvent::Key>(e.key.keysym.sym), SDL_GetModState(), static_cast<bool>(e.key.repeat) };
auto w = focusWidget();
if (!w)
w = widgetByWindowId(e.key.windowID);
else if (w->ancestor() != widgetByWindowId(e.key.windowID))
{
std::cerr << "Unknown windowID " << e.key.windowID << std::endl;
break;
}
while (w)
{
if (w->keyPressEvent(ke))
break;
w = w->parent();
}
break;
}
case SDL_KEYUP:
{
KeyEvent ke { static_cast<KeyEvent::Key>(e.key.keysym.sym), SDL_GetModState(), static_cast<bool>(e.key.repeat) };
auto w = focusWidget();
if (!w)
w = widgetByWindowId(e.key.windowID);
else if (w->ancestor() != widgetByWindowId(e.key.windowID))
{
std::cerr << "Unknown windowID " << e.key.windowID << std::endl;
break;
}
while (w)
{
if (w->keyReleaseEvent(ke))
//.........这里部分代码省略.........
示例8: createLandmarks
//.........这里部分代码省略.........
Eigen::MatrixXf R(m, m); // Measurement noise covariance
Eigen::MatrixXf covariance(n, n); // Estimate error covariance
// Reasonable covariance matrices
covariance << 5., .0, .0,
.0, 5., .0,
.0, .0, 5.;
R << 1.0, 0., 0.,
0., 1.0, 0.,
0., 0., 0.1;
Q << 0.1, 0.1, 0.1,
0.1, 0.1, 0.1,
0.1, 0.1, 0.1;
KalmanFilter kf(DT, A, C, Q, R, covariance);
float t0 = 0.0;
kf.init(t0, x0);
// rendering loop
int i = 0;
while (i < 10000) {
//First clear the renderer
SDL_RenderClear(ren);
//Draw the texture
SDL_SetRenderDrawColor(ren, 200, 200, 255, 255);
SDL_RenderClear(ren); // fill the scene with white
SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
// update renderer
SDL_RenderPresent(ren);
// move robot
SDL_PumpEvents();
const Uint8 *key_pressed = SDL_GetKeyboardState(NULL);
robby.move(key_pressed, control);
// measure landmark positions
auto observed_landmarks = robby.measureLandmarks(landmarks);
// get robot state
Eigen::VectorXf state = robby.get_state();
// Localize via Landmarks
kf.localization_landmarks(observed_landmarks, landmarks, control);
// get estimated state (x,y,phi) as estimated by the EKF
auto x_hat = kf.get_state();
printf("True x,y,phi: %f, %f, %f\n", state(0), state(1),state(2));
printf("Estimated x,y,phi: %f, %f, %f\n", x_hat(0), x_hat(1), x_hat(2));
// move robby estimate to new pose as calculated by kalman filter:
robby_estimate.setPose(x_hat(0), x_hat(1), x_hat(2));
robby_estimate.render(ren);
// render robot
robby.render(ren);
// render landmarks
for (auto lm = landmarks.begin(); lm != landmarks.end(); ++lm)
{
SDL_SetRenderDrawColor(ren, lm->id.r, lm->id.g, lm->id.b, lm->id.a);
lm->render(ren);
}
SDL_SetRenderDrawColor(ren, gray.r, gray.g, gray.b, gray.a);
// render sampled probability distribution
kf.renderSamples(ren);
SDL_RenderPresent(ren);
//Take a quick break after all that hard work
SDL_Delay(30);
if (key_pressed[SDL_SCANCODE_RETURN])
{
printf("Exiting Program!\n");
break;
}
i+=1;
}
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
return EXIT_SUCCESS;
}
示例9: main
//.........这里部分代码省略.........
default:
break;
}
}
else if (event.type == SDL_MOUSEBUTTONDOWN){
if (event.button.button == SDL_BUTTON_LEFT){
camera.mousecontrol_on();
}
else if (event.button.button == SDL_BUTTON_RIGHT){
rightmouse_down = true;
human.bound.xclick = camera.xfrompixel(event.button.x,event.button.y,db::Player);
human.bound.yclick = camera.yfrompixel(event.button.x,event.button.y,db::Player);
human.bound.xdrag = 0;
human.bound.ydrag = 0;
human.bound.enabled = true;
}
}
else if (event.type == SDL_MOUSEBUTTONUP){
if (event.button.button == SDL_BUTTON_LEFT){
camera.mousecontrol_off();
}
else if (event.button.button == SDL_BUTTON_RIGHT){
rightmouse_down = false;
}
}
else if (event.type == SDL_MOUSEWHEEL){
zoomdirection += event.wheel.y;
}
else if (event.type == SDL_MOUSEMOTION){
mousepx = event.motion.x;
mousepy = event.motion.y;
if (camera.mouse_controlling()){
camera.mousecontrol_move(mousepx, mousepy, event.motion.xrel, event.motion.yrel,SDL_GetModState()==KMOD_LCTRL);
}
else{
mousex = camera.xfrompixel(event.motion.x, event.motion.y, db::Player);
mousey = camera.yfrompixel(event.motion.x, event.motion.y, db::Player);
if(mousepx <= 1) camera.pan_leftright(-1);
else if (mousepx >= (int)gamesettings.window_width-1) camera.pan_leftright(1);
else if (mousepx - event.motion.xrel <= 1) camera.pan_leftright(0);
else if (mousepx - event.motion.xrel >= (int)gamesettings.window_width-1) camera.pan_leftright(0);
if(mousepy <= 1) camera.pan_updown(-1);
else if (mousepy >= (int)gamesettings.window_height-1) camera.pan_updown(1);
else if (mousepy - event.motion.yrel <= 1) camera.pan_updown(0);
else if (mousepy - event.motion.yrel >= (int)gamesettings.window_height-1) camera.pan_updown(0);
if(rightmouse_down){
human.bound.xdrag += event.motion.xrel;
human.bound.ydrag += event.motion.yrel;
}
}
}
else if (event.type == SDL_QUIT){
quitnow = true;
}
}
objects.step_time();
SDL_SetRenderDrawColor(renderer, 0,0,0,255);
SDL_RenderClear(renderer);
camera.adjust_zoom(zoomdirection, mousex, mousey);
for (double x = gamesettings.mapx+tilew/2; x < gamesettings.mapx+gamesettings.mapw+tilew/2; x += tilew){
for (double y = gamesettings.mapy+tileh/2; y < gamesettings.mapy+gamesettings.maph+tileh/2; y += tileh){
SDL_Rect dst = camera.calculate_display_destination(x,y,tilew,tileh,db::Floor);
SDL_RenderCopyEx(renderer, bgtile_texture, NULL, &dst, -camera.camyaw*180.0/3.14156033, NULL, SDL_FLIP_NONE);
}
}
objects.drawon(renderer, &camera);
if(console.is_active()) console.drawon(renderer);
human.bound.drawon(renderer, &camera);
Uint32 fps_newframe = SDL_GetTicks();
if((fps_newframe-fps_lastframe) < SCREEN_TICKS_PER_FRAME){
SDL_Delay(SCREEN_TICKS_PER_FRAME - (fps_newframe-fps_lastframe));
}
draw_fps(renderer, font, 1.0/(fps_newframe/1000.0 - fps_lastframe/1000.0));
fps_lastframe = fps_newframe;
SDL_RenderPresent(renderer);
}
SDL_DestroyTexture(character_texture);
SDL_DestroyTexture(bgtile_texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
for(unsigned int i = 0; i < star_field.size(); ++i)
delete star_field[i];
return 0;
}
示例10: render
void render(Scene& scene, Texture& screen, int renderno = 0, int outof = 1) {
char titlebuf[200];
if (settings.show_preview) {
sprintf(titlebuf, "%s", TITLE);
SDL_SetWindowTitle(window, titlebuf);
}
Vect4 color;
bool exitflag = 0;
int v; //Return value from threads
RenderQueue rq(&scene, &screen);
SDL_Thread** threads = new SDL_Thread* [settings.nworkers];
rq.pushRow(0);
for (int i = 0; i < settings.nworkers; i++) threads[i] = SDL_CreateThread(&renderThread, NULL, &rq);
for (int i = 0; i < settings.nworkers; i++) SDL_WaitThread(threads[i], &v);
for (int r = 1; r < screen.height(); r++) {
if (settings.show_preview) {
SDL_Event event;
while (SDL_PollEvent(&event))
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) exit(0);
else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) exitflag = 1;
if (exitflag) break;
}
rq.pushRow(r);
for (int i = 0; i < settings.nworkers; i++) threads[i] = SDL_CreateThread(&renderThread, NULL, &rq);
if (settings.show_preview) {
drawRow(screen, r - 1);
px->redraw();
SDL_RenderPresent(px->getRenderer());
}
for (int i = 0; i < settings.nworkers; i++) SDL_WaitThread(threads[i], &v);
if (outof > 1) sprintf(titlebuf, "%s [%d / %d, %d of %d]",TITLE, r + 1, screen.height(), renderno, outof);
else sprintf(titlebuf, "%s [%d / %d]", TITLE, r + 1, screen.height());
if (settings.show_preview)
SDL_SetWindowTitle(window, titlebuf);
else {
printf("\r%s", titlebuf);
fflush(0);
}
}
if (settings.show_preview) {
drawRow(screen, screen.height() - 1);
px->redraw();
SDL_RenderPresent(px->getRenderer());
}
else printf("\n");
if (!settings.aa_enabled) {
delete [] threads;
return;
}
Texture dmap = screen.differenceMap();
float d;
for (int r = 1; r < screen.height() - 1; r++) {
if (settings.show_preview) {
SDL_Event event;
while (SDL_PollEvent(&event))
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) exit(0);
else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) exitflag = 1;
if (exitflag) break;
}
for (int c = 1; c < screen.width() - 1; c++) {
d = dot(dmap.getColor(r, c), Vect4(1, 1, 1, 0));
if (d > settings.aa_threshold) rq.push(r, c);
}
for (int i = 0; i < settings.nworkers; i++) threads[i] = SDL_CreateThread(&renderThread_AA, NULL, &rq);
if (settings.show_preview) {
drawRow(screen, r - 1);
px->redraw();
SDL_RenderPresent(px->getRenderer());
}
for (int i = 0; i < settings.nworkers; i++) SDL_WaitThread(threads[i], &v);
if (outof > 1) sprintf(titlebuf, "%s [AA: %d / %d, %d of %d]", TITLE, r + 2, screen.height(), renderno, outof);
else sprintf(titlebuf, "%s [AA: %d / %d]",TITLE, r + 2, screen.height());
if (settings.show_preview)
SDL_SetWindowTitle(window, titlebuf);
else {
printf("\r%s", titlebuf);
fflush(0);
}
}
delete [] threads;
//.........这里部分代码省略.........
示例11: vid_thread
//.........这里部分代码省略.........
/* Gesture events */
eventtypes[SDL_DOLLARGESTURE] = "DOLLARGESTURE";
eventtypes[SDL_DOLLARRECORD] = "DOLLARRECORD";
eventtypes[SDL_MULTIGESTURE] = "MULTIGESTURE";
/* Clipboard events */
eventtypes[SDL_CLIPBOARDUPDATE] = "CLIPBOARDUPDATE"; /**< The clipboard changed */
/* Drag and drop events */
eventtypes[SDL_DROPFILE] = "DROPFILE"; /**< The system requests a file open */
/** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
* and should be allocated with SDL_RegisterEvents()
*/
eventtypes[SDL_USEREVENT] = "USEREVENT";
}
sim_debug (SIM_VID_DBG_VIDEO|SIM_VID_DBG_KEY|SIM_VID_DBG_MOUSE, vid_dev, "vid_thread() - Starting\n");
vid_mono_palette[0] = sim_end ? 0xFF000000 : 0x000000FF;
vid_mono_palette[1] = 0xFFFFFFFF;
memset (&vid_key_state, 0, sizeof(vid_key_state));
SDL_Init (SDL_INIT_VIDEO);
SDL_CreateWindowAndRenderer (vid_width, vid_height, SDL_WINDOW_SHOWN, &vid_window, &vid_renderer);
if ((vid_window == NULL) || (vid_renderer == NULL)) {
sim_printf ("%s: Error Creating Video Window: %s\b", sim_dname(vid_dev), SDL_GetError());
SDL_Quit ();
return 0;
}
SDL_SetRenderDrawColor (vid_renderer, 0, 0, 0, 255);
SDL_RenderClear (vid_renderer);
SDL_RenderPresent (vid_renderer);
vid_texture = SDL_CreateTexture (vid_renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
vid_width, vid_height);
if (!vid_texture) {
sim_printf ("%s: Error configuring Video environment: %s\b", sim_dname(vid_dev), SDL_GetError());
SDL_DestroyRenderer(vid_renderer);
vid_renderer = NULL;
SDL_DestroyWindow(vid_window);
vid_window = NULL;
SDL_Quit ();
return 0;
}
SDL_StopTextInput ();
sim_debug (SIM_VID_DBG_VIDEO|SIM_VID_DBG_KEY|SIM_VID_DBG_MOUSE, vid_dev, "vid_thread() - Started\n");
while (vid_active) {
if (SDL_WaitEvent (&event)) {
switch (event.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
vid_key ((SDL_KeyboardEvent*)&event);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
vid_mouse_button ((SDL_MouseButtonEvent*)&event);
break;
case SDL_MOUSEMOTION:
vid_mouse_move ((SDL_MouseMotionEvent*)&event);
break;
case SDL_USEREVENT:
/* There are 2 user events generated */
/* EVENT_REDRAW to update the display */
/* EVENT_CLOSE to wake up this thread and let */
/* it notice vid_active has changed */
if (event.user.code == EVENT_REDRAW)
vid_update ();
break;
default:
sim_debug (SIM_VID_DBG_VIDEO|SIM_VID_DBG_KEY|SIM_VID_DBG_MOUSE, vid_dev, "vid_thread() - Ignored Event: Type: %s(%d)\n", eventtypes[event.type], event.type);
break;
}
}
}
SDL_DestroyTexture(vid_texture);
vid_texture = NULL;
SDL_DestroyRenderer(vid_renderer);
vid_renderer = NULL;
SDL_DestroyWindow(vid_window);
vid_window = NULL;
SDL_Quit ();
sim_debug (SIM_VID_DBG_VIDEO|SIM_VID_DBG_KEY|SIM_VID_DBG_MOUSE, vid_dev, "vid_thread() - Exiting\n");
return 0;
}
示例12: LancerJeu
int LancerJeu(gpointer *pData)
{
/* Cette fonction va appeler les fonctions d'initialisations de la SDL et lancer le jeu ou l'éditeur */
SDL_Renderer *pMoteurRendu = NULL; //Pointeurs sur le moteur de rendu
SDL_Window *pFenetre = NULL; //Pointeur sur la fenêtre
FMOD_CHANNEL *channelEnCours = NULL; //Pour le contrôle des différents canaux audios
Sprite images[50] = {{NULL}, {0,0}}; //Tableau des images (textures + positions)
TTF_Font *polices[10] = {NULL}; //Tableau des polices
Options *pOptions = NULL; //Pointeur sur une structure Options
FILE *pFichierErreur = fopen("ressources/ErreursLog.txt", "a"); //Pointeur sur le fichier d'erreurs
SDL_Surface *surf = NULL; //Pointeur sur une surface
SDL_Texture *pEcranChargement = NULL; //Pointeur sur une texture pour l'écran de chargement
Animation anim[10]; //Tableau de structures Animation
int erreur=0; //Code d'erreur
Joueur *pJoueur = (Joueur *)g_slist_nth_data((GSList*)pData, 6); //On récupère le pointeur vers la structure Joueur dans la liste chaînée
Sons *pSons = (Sons*)g_slist_nth_data((GSList*)pData, 4); //De même avec celui vers la structure Sons
FMOD_SYSTEM *pMoteurSon = (FMOD_SYSTEM *)g_slist_nth_data((GSList*)pData, 3); //De même avec celui vers la structure FMOD_SYSTEM
if(pFichierErreur == NULL) //Vérification
{
exit(EXIT_FAILURE);
}
/* On lit les options et on remplit la structure */
pOptions = DefinirOptions();
Initialisation(&pMoteurRendu, pFichierErreur, &pFenetre, pOptions); //Initialisation des principaux éléments (SDL, fenêtre, moteur de rendu)
FMOD_System_GetChannel(pMoteurSon, M_MENU, &channelEnCours); //On met en pause la musique du menu
FMOD_Channel_SetPaused(channelEnCours, true);
if(BMusique) //S'il y a de la musique
{
FMOD_System_PlaySound(pMoteurSon, M_LOAD, pSons->music[M_LOAD], true, NULL); // On lit la musique de chargement
FMOD_System_GetChannel(pMoteurSon, M_LOAD, &channelEnCours);
FMOD_Channel_SetVolume(channelEnCours, (float)(Volume/100.0));
FMOD_Channel_SetPaused(channelEnCours, false);
}
/* On charge l'image de chargement et on vérifie */
surf = IMG_Load("ressources/img/load.png");
if (surf == NULL)
{
fprintf(pFichierErreur, "Erreur: impossible d'ouvrir le fichier ressources/img/load.png");
exit(EXIT_FAILURE);
}
/* On transforme la surface en texture pour l'affichage et on libère la mémoire occupée par la surface */
pEcranChargement = SDL_CreateTextureFromSurface(pMoteurRendu, surf);
SDL_FreeSurface(surf);
SDL_ShowCursor(false); //On masque le curseur pendant le jeu (on affichera un curseur personnalisé dans l'éditeur)
/* On efface l'écran et on colle l'image de chargement */
SDL_SetRenderDrawColor(pMoteurRendu, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(pMoteurRendu);
SDL_RenderCopy(pMoteurRendu, pEcranChargement, NULL, NULL);
SDL_RenderPresent(pMoteurRendu);
SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE); //Désactivation des événements dont on a pas besoin.
SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
SDL_DisableScreenSaver(); //Désactivation de l'écran de veille.
erreur = Chargements(images, pMoteurRendu, polices, anim); //On charge tout !
/* Traitement des éventuelles erreurs */
if(erreur == 1)
{
fprintf(pFichierErreur, "Erreur lors du chargement des images. Veuillez vérifier ressources\\img\\... \n");
exit(EXIT_FAILURE);
}
else if (erreur == 2)
{
fprintf(pFichierErreur, "Erreur lors du chargement des polices. Veuillez vérifier ressources\\fonts\\... \n");
exit(EXIT_FAILURE);
}
else if (erreur == 3)
{
fprintf(pFichierErreur, "Erreur lors du chargement des animations. Veuillez vérifier ressources\\anim\\... \n");
exit(EXIT_FAILURE);
}
if (BMusique)
{
FMOD_System_GetChannel(pMoteurSon, M_LOAD, &channelEnCours); //On arrête la musique du chargement
FMOD_Channel_SetPaused(channelEnCours, true);
FMOD_Sound_SetLoopCount(pSons->music[M_JEU], -1); // On active la lecture en boucle
FMOD_System_PlaySound(pMoteurSon, M_JEU, pSons->music[M_JEU], true, NULL); // On lit la musique du jeu
//.........这里部分代码省略.........
示例13: switch
void gfxengine_t::flip()
{
if(!screen_surface)
return;
// Init dirtyrect table flipping, if necessary.
switch(_pages)
{
case -1:
if(!_doublebuf)
frontpage = backpage = 0;
else if(frontpage == backpage)
{
frontpage = 0;
backpage = 1;
}
break;
case 0:
frontpage = backpage = 0;
invalidate();
break;
case 1:
frontpage = backpage = 0;
break;
case 2:
case 3:
if(frontpage == backpage)
{
frontpage = 0;
backpage = 1;
}
break;
}
// Process the dirtyrects.
int i;
for(i = 0; i < dirtyrects[backpage]; ++i)
{
if(dirtywtable[backpage][i])
{
if(!dirtywtable[backpage][i]->visible())
continue;
SDL_Rect dr = dirtytable[backpage][i];
dirtywtable[backpage][i]->phys_refresh(&dr);
}
else
refresh_rect(&dirtytable[backpage][i]);
}
// Perform the actual flip or update
if(_shadow)
{
for(i = 0; i < dirtyrects[backpage]; ++i)
SDL_BlitSurface(softbuf,
&dirtytable[backpage][i],
screen_surface,
&dirtytable[backpage][i]);
}
if(_doublebuf)
{
dirtyrects[backpage] = 0;
if(_pages == -1)
{
backpage = !backpage;
frontpage = !frontpage;
}
else if(_pages > 1)
{
backpage = (backpage + 1) % _pages;
frontpage = (frontpage + 1) % _pages;
}
SDL_UpdateTexture(sdlTexture, NULL, screen_surface->pixels, screen_surface->pitch);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, sdlTexture, NULL, NULL);
SDL_RenderPresent(renderer);
// SDL_UpdateWindowSurface(myscreen);
// SDL_Flip(screen_surface);
// SDL_RenderPresent(SDL_CreateSoftwareRenderer(screen_surface));
}
else
{
SDL_UpdateTexture(sdlTexture, NULL, screen_surface->pixels, screen_surface->pitch);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, sdlTexture, NULL, NULL);
SDL_RenderPresent(renderer);
// SDL_UpdateWindowSurface(myscreen);
// SDL_UpdateRects(screen_surface, dirtyrects[0], dirtytable[0]);
// SDL_RenderPresent(SDL_CreateSoftwareRenderer(screen_surface));
dirtyrects[0] = 0;
}
}
示例14: SDL_SetRenderDrawColor
void SDLApp::OnFrame(float dt)
{
SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 255);
SDL_RenderClear(renderer_);
SDL_RenderPresent(renderer_);
}
示例15: SDL_RenderPresent
void CSDL_setup::end()
{
SDL_RenderPresent(renderer);
}