Make compatible with the Sun's pixel format
This commit is contained in:
parent
a1c39be7b3
commit
98b2b4c64d
2 changed files with 19 additions and 28 deletions
|
@ -27,8 +27,9 @@ static unsigned long startTime;
|
|||
bool Backend_Init(void (*drag_and_drop_callback)(const char *path), void (*window_focus_callback)(bool focus)) {
|
||||
// we're ignoring the hell out of focus and drag & drop
|
||||
xDisplay = XOpenDisplay(NULL);
|
||||
//XMatchVisualInfo(xDisplay, DefaultScreen(xDisplay), 24, DirectColor, &xvisinfo);
|
||||
//xVisual = xvisinfo.visual;
|
||||
XMatchVisualInfo(xDisplay, DefaultScreen(xDisplay), 24, TrueColor, &xvisinfo);
|
||||
xVisual = xvisinfo.visual;
|
||||
printf("Using X visual with ID 0x%lx\n", xVisual->visualid);
|
||||
|
||||
struct timeval time; // time.tv_usec is microseconds
|
||||
gettimeofday(&time, NULL);
|
||||
|
|
|
@ -12,7 +12,7 @@ static Window window;
|
|||
static XImage* framebufferImage;
|
||||
static char* framebufferPixels;
|
||||
static int framebufferPitch;
|
||||
static char* xfriendlyFB;
|
||||
static unsigned char* xfriendlyFB;
|
||||
static GC gc;
|
||||
static int screenWidth;
|
||||
static int screenHeight;
|
||||
|
@ -26,8 +26,9 @@ bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen
|
|||
|
||||
int screen = DefaultScreen(xDisplay);
|
||||
Window rootWindow = RootWindow(xDisplay, screen);
|
||||
//window = XCreateWindow(display, rootWindow, 0, 0, screen_width, screen_height, 0, 16, InputOutput, CopyFromParent, 0, NULL);
|
||||
window = XCreateSimpleWindow(xDisplay, rootWindow, 0, 0, screen_width, screen_height, 1, 0, 0);
|
||||
|
||||
window = XCreateWindow(xDisplay, rootWindow, 0, 0, screen_width, screen_height, 0, 24, InputOutput, xVisual, 0, NULL);
|
||||
//window = XCreateSimpleWindow(xDisplay, rootWindow, 0, 0, screen_width, screen_height, 1, 0, 0);
|
||||
XSelectInput(xDisplay, window, ExposureMask | KeyPressMask | KeyReleaseMask);
|
||||
XMapRaised(xDisplay, window);
|
||||
XStoreName(xDisplay, window, window_title);
|
||||
|
@ -45,10 +46,10 @@ bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen
|
|||
|
||||
// Setting up the framebuffer
|
||||
framebufferPixels = (char*)malloc(screen_width * screen_height * 3);
|
||||
xfriendlyFB = (char*)malloc(screen_width * screen_height * 4);
|
||||
framebufferImage = XCreateImage(xDisplay, DefaultVisual(xDisplay, DefaultScreen(xDisplay)),
|
||||
xfriendlyFB = (unsigned char*)malloc(screen_width * screen_height * 4);
|
||||
framebufferImage = XCreateImage(xDisplay, xVisual,//DefaultVisual(xDisplay, DefaultScreen(xDisplay)),
|
||||
depth, ZPixmap, 0,
|
||||
xfriendlyFB, screen_width, screen_height,
|
||||
(char*)xfriendlyFB, screen_width, screen_height,
|
||||
32, 0);
|
||||
if(framebufferImage == 0) {
|
||||
return false;
|
||||
|
@ -76,28 +77,17 @@ void WindowBackend_Software_HandleWindowResize(size_t width, size_t height) {
|
|||
}
|
||||
|
||||
void WindowBackend_Software_Display(void) {
|
||||
// Convert Cave Story's framebuffer format to the Sun's
|
||||
// This is the exact reverse of how it is on modern
|
||||
// computers. Yup, it's endianess.
|
||||
int srci = 0;
|
||||
for(int i = 0; i < screenWidth * screenHeight * 4; i++) {
|
||||
for(int i = 0; i < screenWidth * screenHeight * 4; i += 4) {
|
||||
int src;
|
||||
switch(i % 4) {
|
||||
case 0:
|
||||
src = srci + 2;
|
||||
break;
|
||||
case 1:
|
||||
src = srci + 1;
|
||||
break;
|
||||
case 2:
|
||||
src = srci + 0;
|
||||
break;
|
||||
case 3:
|
||||
xfriendlyFB[i + 0] = 0; // UNUSED
|
||||
xfriendlyFB[i + 1] = framebufferPixels[srci + 2]; // BLUE
|
||||
xfriendlyFB[i + 2] = framebufferPixels[srci + 1]; // GREEN
|
||||
xfriendlyFB[i + 3] = framebufferPixels[srci + 0]; // RED
|
||||
srci += 3;
|
||||
}
|
||||
xfriendlyFB[i] = framebufferPixels[src];
|
||||
// if(i % 4 != 3) {
|
||||
// xfriendlyFB[i] = framebufferPixels[srci];
|
||||
// srci++;
|
||||
// }
|
||||
}
|
||||
XPutImage(xDisplay, window, gc, framebufferImage, 0, 0, 0, 0, screenWidth, screenHeight);
|
||||
//XCopyArea(xDisplay, intermediate, window, gc, 0, 0, screenWidth, screenHeight, 0, 0);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue