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 @@ heightƒT[ƒtƒFƒCƒX‚̍‚‚³ depthƒT[ƒtƒFƒCƒX‚̃rƒbƒg[“x pitchpixels‚̐…•½•ûŒü‚̃oƒCƒg” -formatƒT[ƒtƒFƒCƒX‚̃tƒH[ƒ}ƒbƒg +formatƒT[ƒtƒFƒCƒX‚̃sƒNƒZƒ‹Œ`Ž®

–ß‚è’l

¬Œ÷‚Ì‚Æ‚«¶¬‚³‚ꂽSDL_Surface, Ž¸”s‚Ì‚Æ‚«NULL‚ð–ß‚·. SDL_GetError()‚ðŒÄ‚ñ‚ŏڍׂð’m‚邱‚Æ‚ª‚Å‚«‚é. +

ƒTƒ“ƒvƒ‹ƒR[ƒh

+

+ +

+// stb_image.h‚ðŽg‚Á‚ēǂݍž‚ñ‚¾‰æ‘œƒtƒ@ƒCƒ‹‚©‚çSDL_Surface*‚𐶐¬‚·‚éƒTƒ“ƒvƒ‹
+// (https://github.com/nothings/stb/)
+
+// stb_image‚É—v‹‚·‚éo—͂̃Jƒ‰[Œ`Ž®
+// ƒ¿ƒ`ƒƒƒlƒ‹‚ð‹‚ß‚È‚¢/•K—v‚È‚¢‚È‚ç‚Î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; // 1ƒsƒNƒZƒ‹‚ ‚½‚è3byte * 1s‚̃sƒNƒZƒ‹”
+    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[ƒtƒFƒCƒX‚̐¶¬‚ÉŽ¸”s‚µ‚½: %s", SDL_GetError());
+    stbi_image_free(data);
+    exit(1);
+}
+
+// ... ‚±‚±‚ŃT[ƒtƒFƒCƒX‚ðŽg‚¤ ...
+// ...
+
+// ƒT[ƒtƒFƒCƒX‚ª•K—v‚È‚­‚È‚Á‚½‚ç‰ð•ú‚·‚é...
+SDL_FreeSurface(surf);
+// .. *‚»‚µ‚Ä* ƒT[ƒtƒFƒCƒX‚ÅŽg‚Á‚½ƒf[ƒ^‚à!
+stbi_image_free(data);
+
+ +

Ú×

ƒƒ‚ƒŠ‚ðŠm•Û‚Å‚«‚È‚©‚Á‚½‚Æ‚«‚ÍNULL‚ð–ß‚·.

+

+ƒsƒNƒZƒ‹ƒf[ƒ^‚̓Rƒs[‚³‚ê‚È‚¢. +ƒsƒNƒZƒ‹ƒf[ƒ^‚ÍŽ©“®“I‚ÉŠÇ—‚³‚ê‚È‚¢. ‚‚܂è, ƒsƒNƒZƒ‹ƒf[ƒ^‚ð‰ð•ú‚·‚é‘O‚ɃT[ƒtƒFƒCƒX‚ð‰ð•ú‚·‚é•K—v‚ª‚ ‚é. +

ƒo[ƒWƒ‡ƒ“

‚±‚̊֐”‚ÍSDL 2.0.5ˆÈ~‚ÅŽg‚¦‚é.

ŠÖ˜A€–Ú(ŠÖ”)

+SDL_CreateRGBSurfaceFrom
SDL_CreateRGBSurfaceWithFormat
SDL_FreeSurface

SDL Wiki‚ւ̃Šƒ“ƒN