`
haoningabc
  • 浏览: 1444296 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

sdl笔记

阅读更多
sdl教程教程
https://github.com/Twinklebear/TwinklebearDev-Lessons

asm.js的教程
https://github.com/3dgen/cppwasm-book
入门
http://www.ruanyifeng.com/blog/2017/09/asmjs_emscripten.html



#######
vim格式化:
1,gg 跳转到第一行
2,shift+v 转到可视模式
3,shift+g 全选
4,按下神奇的 =


centos7安装

yum install SDL SDL-devel SDL-static -y
helloworld
https://www.linuxidc.com/Linux/2012-12/75255.htm

main.c
#include "SDL/SDL.h"  
int main( int argc, char* args[] )  
{  
    //Start SDL  
    SDL_Init( SDL_INIT_EVERYTHING );  
    //Quit SDL  
    SDL_Quit();  
    return 0;      
} 

加载一张图片
在mac下的例子参考
https://github.com/killinux/ffmpeg-leaning/tree/master/sdl/sdl_practic_1
或者我的mtcode
#include <iostream>
extern "C" {
#include <SDL2/SDL.h>
#include <SDL2/SDL_test_images.h>
}
using namespace  std;

const int WIDTH = 960, HEIGHT = 540;
int main() {

    SDL_Surface *imageSurface = NULL;
    SDL_Surface *windowSurface = NULL;

    if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        cout << "SDL could not initialized with error: " << SDL_GetError() << endl;
    }
    SDL_Window *window = SDL_CreateWindow("Hello SDL world!", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                          WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI);
    if (NULL == window) {
        cout << "SDL could not create window with error: " << SDL_GetError() << endl;
    }

    windowSurface = SDL_GetWindowSurface(window);
    imageSurface = SDL_LoadBMP("little_prince.bmp");
    if (NULL == imageSurface) {
        cout << "SDL could not load image with error: " << SDL_GetError() << endl;
    }
    SDL_Event windowEvent;
    while(true) {
        if (SDL_PollEvent(&windowEvent)) {
            if (SDL_QUIT == windowEvent.type) {
                cout << "SDL quit!!" << endl;
                break;
            }
        }

        SDL_BlitSurface(imageSurface, NULL, windowSurface, NULL);
        SDL_UpdateWindowSurface(window);
    }

    imageSurface = NULL;
    windowSurface = NULL;
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

emscripten 加载文件
https://github.com/3dgen/cppwasm-book/blob/master/zh/ch3-runtime/ch3-03-fs.md






############################


emcc使用sdl2
emcc main.c -s USE_SDL=2 -o main.html

[url]https://www.jamesfmackenzie.com/2019/12/01/webassembly-graphics-with-sdl/
[/url]

https://blog.csdn.net/pkx1993/article/details/82015659?utm_source=blogxgwz4

Emscripten Ports

有用库的收集,并移植到Emscripten。Github地址:https://github.com/emscripten-ports

他们已经被整合到了emcc中。当你请求一个ports被使用时,emcc会从远程服务器获取,设置并在本地构建它,然后将其链接到您的项目,向您的构建命令添加必需的包含。
例如:SDL2是一个ports,可以请求并并使用命令-s USE_SDL=2链接他。

emcc tests/sdl2glshader.c -s USE_SDL=2 -s LEGACY_GL_EMULATION=1 -o sdl2.html

###############
SDL入门教程:
https://segmentfault.com/a/1190000011328496

emscripten 加载sdl的helloworld
hello_world_cube.cpp
#include <stdio.h>
#include <SDL/SDL.h>

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif

extern "C" int main(int argc, char** argv) {
  printf("hello, world!\n");

  SDL_Init(SDL_INIT_VIDEO);
  SDL_Surface *screen = SDL_SetVideoMode(256, 256, 32, SDL_SWSURFACE);

#ifdef TEST_SDL_LOCK_OPTS
  EM_ASM("SDL.defaults.copyOnLock = false; SDL.defaults.discardOnLock = true; SDL.defaults.opaqueFrontBuffer = false;");
#endif

  if (SDL_MUSTLOCK(screen)) SDL_LockSurface(screen);
  for (int i = 0; i < 256; i++) {
    for (int j = 0; j < 256; j++) {
#ifdef TEST_SDL_LOCK_OPTS
      // Alpha behaves like in the browser, so write proper opaque pixels.
      int alpha = 255;
#else
     // To emulate native behavior with blitting to screen, alpha component is ignored. Test that it is so by outputting
      // data (and testing that it does get discarded)
      int alpha = (i+j) % 255;
#endif
      *((Uint32*)screen->pixels + i * 256 + j) = SDL_MapRGBA(screen->format, i, j, 255-i, alpha);
    }
  }
  if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
  SDL_Flip(screen);

  printf("you should see a smoothly-colored square - no sharp lines but the square borders!\n");
  printf("and here is some text that should be HTML-friendly: amp: |&| double-quote: |\"| quote: |'| less-than, greater-than, html-like tags: |<cheez></cheez>|\nanother line.\n");

  SDL_Quit();

  return 0;
}


########
问题:
1.浏览器最基本的sdl
2.加载图片?


















分享到:
评论

相关推荐

    SDL库移植笔记

    记录了SDL库成功移植到s3c6410开发板上,很详细,帮你完成移植工作

    SDL(MinGW)

    这是用于MinGW的SDL库。安装时只需解压文件并将对应文件放入MinGW编译器根目录对应文件夹即可,详情请阅读我的文章《SDL2学习笔记(一):SDL2初步》,其中记录了详细安装教程。

    linux下V4L2+SDL摄像头采集显示程序

    使用video4linux2编程接口,获得笔记本摄像头影像后,用SDL显示在X Window下。 关键点有二:其一,从video4linux2的编程接口笔者了解到其笔记本摄像头支持YUYV视频帧格式,显示在 SDL上需要将YUYV格式转换成SDL支持...

    SDL2和OpenGL使用踩坑笔记经验分享

    SDL + OpenGL使用笔记 LFTK 是一个嵌入式GUI,为了开发方便,需要提供PC运行环境。我选择了SDL2+OpenGL+nanovg来实现底层的渲染,让LFTK可以运行在各个平台上。GLFW+OpenGL也是一个不错的选择,但是GLFW没有Android...

    快乐成长贪吃蛇(Linux+C+SDL)

    项目围绕贪吃蛇为原型,以做数学题为驱动,集学习娱乐为一体,应用于100美元笔记本.

    wasm_sdl2_test:WebAssembly + SDL2的测试

    使用SDL2进行WebAssembly的小测试 播放背景音乐时,一个球在画布上弹跳。 当球击中墙壁时发出声音效果。...笔记 我只有通过将--preload-file添加到CFLAGS才能使文件加载与emscripten一起使用。 反过来,这仅适用于_

    SDL2-Xcode-Template:用于 XCode 的 SDL2 Xcode 模板(4.5.2 测试)

    请添加到 SDL2 Base.xctemplate/TemplateInfo.plist @ 底部,靠近 LIBRARY_SEARCH_PATHS :) 你会明白的:)安装要安装模板,只需将 Project Templates 文件夹复制到 ~/Library/Developer/Xcode/Templates笔记有 ...

    snake-sdl2:SDL2中的经典蛇游戏

    这是诺基亚黑白屏时代的蛇游戏。... 笔记 使用箭头键浏览菜单并操纵蛇,然后按Enter选择菜单。 使用SDL2显示2D GUI和游戏。 用make编译。 用make run运行。 用清洁使干净。 作者 Shubham Chaudhary 干杯!

    对TinyPTC-SDL-0.3.2库的更新,通过cairo示例显示中文

    TinyPTC-SDL可通过cairo显示汉字,增加使用方便性,配合笔记示例可实操使用。

    RT-Thread Smart的一些技术笔记

    RT-Thread Smart的一些技术笔记。【ART-Pi Smart】上手体验以及 vscode 插件使用。【ART-Pi Smart】使用 VS Code 开发 GUI 应用。【ART-Pi Smart】基于 FFmpeg + SDL2 实现视频播放。【ART-Pi Smart】基于 SDL2 进行...

    chapel-sdl:Chapel 的 SDL 绑定

    教堂-sdl Chapel 的 SDL 绑定 ...Message mjk8ball through github ...笔记! The --llvm chpl compiler flag causes the following error: internal error: SYM0636 chpl Version 1.10.0.3a08ce3 The --fast

    GEngine-R:基于SDL2的2D游戏引擎

    基于SDL2构建的2D游戏引擎。 重写了我的一个旧项目。 这是一个进行中的项目,请不要提供支持。 重要笔记: 没什么值得一提的。 去做: 基本引擎循环 帧/逻辑时序 输入处理程序 基于对象/场景的渲染 对象/实例...

    sokoban:老游戏经常编码开始。 旨在了解 SDL SDL2 的工作原理

    推箱子世界上最重制的游戏,是学习 C 或 C++ 的一部分。 这是渲染的概述(用 C 开发)键盘默认键: 上、下、左、右:代表玩家的方块的位移, 退出键:返回菜单...笔记学习SDL/SDL2(系统理解,尤其是日常使用的适应)。

Global site tag (gtag.js) - Google Analytics