C + + Development SDL2 application under Ubuntu14.04

Source: Internet
Author: User
Tags clear screen

1 Download and install

To http://www.libsdl.org/download Http://www.libsdl.org/release/SDL2-2.0.3.zip source code

After decompression

./configure

Make

sudo make install

Check

Header file:/USR/LOCAL/INCLUDE/SDL2

Library Location:/usr/local/lib


2 Establishing the test procedure:

#include <iostream> #include <SDL.h> #define WIDTH 640#define HEIGHT 480#define BPP 4#define DEPTH 32using Name    Space Std;int Main (int argc, char* argv[]) {sdl_surface *screen;    Sdl_event Event;    int keypress = 0;    int h = 0;    if (Sdl_init (sdl_init_everything) = =-1) {cout << "error:" << sdl_geterror () << Endl;    return 1; } sdl_window* Window = Sdl_createwindow ("Hello", sdl_windowpos_centered, sdl_windowpos_centered, 640, 480, SDL_WIND    Ow_shown);        if (window = = NULL) {cout << "Error:" << sdl_geterror () << Endl;    return 1; }sdl_renderer* Renderer = sdl_createrenderer (window,-1, sdl_renderer_accelerated |    Sdl_renderer_presentvsync);        if (renderer = = NULL) {cout << "Error:" << sdl_geterror () << Endl;    return 1; }sdl_surface* Surface = sdl_loadbmp ("Bk.bmp"); sdl_texture* Texture = sdl_createtexturefromsurface (renderer, surface); Sdl_freesurface (surface); Sdl_renderClear (renderer);    Clear Screen sdl_rendercopy (renderer, texture, 0, 0);    Draw the texture to the renderer sdl_renderpresent (renderer);        while (!keypress) {//drawscreen (screen, h++);                    while (Sdl_pollevent (&event)) {switch (event.type) {case Sdl_quit:                    KeyPress = 1;                Break                    Case sdl_keydown:keypress = 1;            Break    }}} sdl_quit (); return 0;}

3 Write the compiled command build file, as follows:

g++ Sdl_app1.cpp-i/usr/local/include/sdl2-l/usr/local/lib-lsdl2-lpthread

To set execution permissions for this file:

chmod +x Build

Run the Compile command:

./build

Generate Execution File a.out


4 Running the program

./a.out

If you cannot find the. so.0 ..., the case where the dynamic link library cannot be found

To run the command:

sudo vim/etc/ld.so.conf #修改系统共享库搜索路径

Increase in the first line

Include/usr/local/lib

Run the command again:

sudo ldconfig

Run./a.out

The results are working correctly





C + + Development SDL2 application under Ubuntu14.04

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.