Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void gClearScreen(CColor* color)
- {
- float r = (float)color->r / 255;
- float g = (float)color->g / 255;
- float b = (float)color->b / 255;
- glClearColor(r, g, b, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- }
- #define GL_UNSIGNED_SHORT_5_6_5 0x8363
- #define TEXTURE_COLORKEY 63519
- void gPrepareBitmap(CBitmap* bmp)
- {
- GLuint tex[1];
- glGenTextures(1, &tex);
- sysLogf("Uploading texture %dx%d\n", bmp->width, bmp->height);
- unsigned char* data = (unsigned char*)malloc(bmp->width * bmp->height * 4);
- // Quick endian flip & color-space conversion
- for (int i = 0; i < bmp->width * bmp->height; i++)
- {
- unsigned short pixel = *((unsigned short*)&bmp->pixels[i * 2]);
- float r = (float)(pixel & 31) / 32;
- float g = (float)((pixel >> 5) & 63) / 64;
- float b = (float)(pixel >> 11) / 32;
- data[i * 4 + 2] = (unsigned char)(r * 255);
- data[i * 4 + 1] = (unsigned char)(g * 255);
- data[i * 4] = (unsigned char)(b * 255);
- data[i * 4 + 3] = pixel == TEXTURE_COLORKEY ? 0 : 255;
- }
- glBindTexture(GL_TEXTURE_2D, tex[0]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmp->width, bmp->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
- free(data);
- bmp->_platData = tex[0];
- }
- void gDrawBitmap(CBitmap* bmp, int x, int y)
- {
- gDrawBitmapEx(bmp, x, y, 0, 0);
- }
- void gDrawBitmapEx(CBitmap* bmp, int x, int y, CColor* colorKey, CColor* mulColor)
- {
- if (!bmp->_platData)
- gPrepareBitmap(bmp);
- glBindTexture(GL_TEXTURE_2D, (GLuint)bmp->_platData);
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2i(x, y);
- glTexCoord2f(1, 0);
- glVertex2i(x + bmp->width, y);
- glTexCoord2f(1, 1);
- glVertex2i(x + bmp->width, y + bmp->height);
- glTexCoord2f(0, 1);
- glVertex2i(x, y + bmp->height);
- glEnd();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement