From df88871b1354c001ec7b6d707ca91d0f3a76f74e Mon Sep 17 00:00:00 2001 From: Justin Marshall Date: Wed, 17 Jun 2020 17:08:45 -0700 Subject: [PATCH] Added 8bit image upload code. --- code/REDALERT/Image.h | 3 ++- code/REDALERT/WINSTUB.CPP | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/code/REDALERT/Image.h b/code/REDALERT/Image.h index 6028300..57b88bf 100644 --- a/code/REDALERT/Image.h +++ b/code/REDALERT/Image.h @@ -23,4 +23,5 @@ __forceinline Image_t::~Image_t() { } } -Image_t* Image_LoadImage(const char* name); \ No newline at end of file +Image_t* Image_LoadImage(const char* name); +Image_t* Image_CreateImageFrom8Bit(const char* name, int Width, int Height, char* data); \ No newline at end of file diff --git a/code/REDALERT/WINSTUB.CPP b/code/REDALERT/WINSTUB.CPP index 6e4fbf7..e9dbb29 100644 --- a/code/REDALERT/WINSTUB.CPP +++ b/code/REDALERT/WINSTUB.CPP @@ -144,6 +144,50 @@ Image_t* Image_LoadImage(const char* name) { return image; } +Image_t* Image_CreateImageFrom8Bit(const char* name, int Width, int Height, char *data) { + // Check to see if the image is already loaded. + for (int i = 0; i < loaded_images.size(); i++) { + if (!strcmp(loaded_images[i]->name, name)) { + return loaded_images[i]; + } + } + + Image_t* image = new Image_t(); + image->buffer = new unsigned char[Width * Height * 4]; + + for (int i = 0; i < Width * Height; i++) { + char c = data[i]; + + image->buffer[(i * 4) + 0] = backbuffer_palette[(c * 3) + 0]; + image->buffer[(i * 4) + 1] = backbuffer_palette[(c * 3) + 1]; + image->buffer[(i * 4) + 2] = backbuffer_palette[(c * 3) + 2]; + if (c == 0) { + image->buffer[(i * 4) + 3] = 0; + } + else { + image->buffer[(i * 4) + 3] = 255; + } + } + + + GLuint texture; + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->buffer); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + + + strcpy(image->name, name); + image->image = texture; + image->width = Width; + image->height = Height; + loaded_images.push_back(image); + return image; +} + + BOOL Set_Video_Mode(HWND hwnd, int w, int h, int bits_per_pixel) { // Todo implement resoluton scaling. return true; // Always return true;