X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=SDL_CreateRGBSurfaceWithFormatFrom.html;h=9517fb0c351ce2ccd63a627228e497973c806b58;hb=3c2c2ef8f709c4feab328057380a6e6e78548674;hp=6ce9dbdd9ab168c46572477561cee84a3d4e3603;hpb=31c0e75eb3949911e3fd4a70cf7c9eaa3cab3408;p=sdl2referencejp%2Fsdl2referencejp.git diff --git a/SDL_CreateRGBSurfaceWithFormatFrom.html b/SDL_CreateRGBSurfaceWithFormatFrom.html index 6ce9dbd..9517fb0 100644 --- a/SDL_CreateRGBSurfaceWithFormatFrom.html +++ b/SDL_CreateRGBSurfaceWithFormatFrom.html @@ -22,20 +22,73 @@
+
+
+
+// stb_image.hðgÁÄÇÝñ¾æt@C©çSDL_Surface*𶬷éTv
+// (https://github.com/nothings/stb/)
+
+// stb_imageÉv·éoÍÌJ[`®
+// ¿`lðßÈ¢/KvÈ¢ÈçÎSTBI_rgbðg¤±Æ
+int req_format = STBI_rgb_alpha;
+int width, height, orig_format;
+unsigned char* data = stbi_load("./test.png", &width, &height, &orig_format, req_format);
+if (data == NULL) {
+ SDL_Log("æÌÇÝÝɸsµ½: %s", stbi_failure_reason());
+ exit(1);
+}
+
+int depth, pitch;
+Uint32 pixel_format;
+if (req_format == STBI_rgb) {
+ depth = 24;
+ pitch = 3*width; // 1sNZ ½è3byte * 1sÌsNZ
+ pixel_format = SDL_PIXELFORMAT_RGB24;
+} else { // STBI_rgb_alpha (RGBA)
+ depth = 32;
+ pitch = 4*width;
+ pixel_format = SDL_PIXELFORMAT_RGBA32;
+}
+
+SDL_Surface* surf = SDL_CreateRGBSurfaceWithFormatFrom((void*)data, width, height,
+ depth, pitch, pixel_format);
+
+if (surf == NULL) {
+ SDL_Log("T[tFCX̶¬É¸sµ½: %s", SDL_GetError());
+ stbi_image_free(data);
+ exit(1);
+}
+
+// ... ±±ÅT[tFCXðg¤ ...
+// ...
+
+// T[tFCXªKvÈÈÁ½çðú·é...
+SDL_FreeSurface(surf);
+// .. *»µÄ* T[tFCXÅgÁ½f[^à!
+stbi_image_free(data);
+
+
ðmÛÅ«È©Á½Æ«ÍNULLðß·.
++sNZf[^ÍRs[³êÈ¢. +sNZf[^Í©®IÉdzêÈ¢. ÂÜè, sNZf[^ððú·éOÉT[tFCXððú·éKvª é. +
±ÌÖÍSDL 2.0.5È~Åg¦é.