From adc9cc08167946927fa21f86d70ce0a0b9630baa Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 6 Jul 2012 16:06:26 +0100 Subject: Move graphics into seperate folder diff --git a/.gitignore b/.gitignore index f578a18..0b98e5c1 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,7 @@ Makefile.me *.manifest *.manifest.res *.pdb -*.sublime-* \ No newline at end of file +*.sublime-* +*.project +*.cproject +*.settings \ No newline at end of file diff --git a/data/hmap.h b/data/hmap.h index 61a1072..cc7acbb 100644 --- a/data/hmap.h +++ b/data/hmap.h @@ -19,7 +19,6 @@ */ #ifndef HMAP_H #define HMAP_H -#include "Graphics.h" static char color_data[] = {0x2B,0x00,0xFF,0x2B,0x00,0xFF,0x28,0x04,0xFF,0x24,0x08,0xFF,0x20,0x0D,0xFF,0x1C,0x12,0xFF,0x17,0x18,0xFF,0x12,0x1E,0xFF,0x0D,0x25,0xFF,0x07,0x2D,0xFF,0x03,0x35,0xFF,0x01,0x3E,0xFF,0x00,0x42,0xFF,0x00,0x44,0xFF,0x00,0x48,0xFF,0x00,0x4A,0xFF,0x00,0x4D,0xFF,0x00,0x51,0xFF,0x00,0x54,0xFF,0x00,0x58,0xFF,0x00,0x5C,0xFF,0x00,0x5E,0xFF,0x00,0x62,0xFF,0x00,0x66,0xFF,0x00,0x6A,0xFF,0x00,0x6D,0xFF,0x00,0x71,0xFF,0x00,0x75,0xFF,0x00,0x79,0xFF,0x00,0x7C,0xFF,0x00,0x7F,0xFF,0x00,0x83,0xFF,0x00,0x87,0xFF,0x00,0x8B,0xFF,0x00,0x8F,0xFF,0x00,0x92,0xFF,0x00,0x96,0xFF,0x00,0x99,0xFF,0x00,0x9C,0xFF,0x00,0xA0,0xFF,0x00,0xA3,0xFF,0x00,0xA7,0xFF,0x00,0xAA,0xFF,0x00,0xAD,0xFF,0x00,0xAE,0xFE,0x00,0xB1,0xFE,0x00,0xB3,0xFE,0x00,0xB6,0xFE,0x00,0xB9,0xFE,0x00,0xBB,0xFD,0x00,0xBD,0xFD,0x00,0xC0,0xFD,0x00,0xC2,0xFD,0x00,0xC5,0xFD,0x00,0xC7,0xFD,0x00,0xC9,0xFD,0x00,0xCC,0xFC,0x00,0xCF,0xFD,0x00,0xD0,0xFC,0x00,0xD3,0xFC,0x00,0xD5,0xFC,0x00,0xD7,0xFB,0x00,0xDA,0xFB,0x00,0xDC,0xFB,0x00,0xDE,0xFB,0x00,0xE1,0xFA,0x00,0xE3,0xF9,0x00,0xE6,0xF9,0x00,0xE7,0xF9,0x00,0xEA,0xF8,0x00,0xEB,0xF7,0x00,0xED,0xF7,0x00,0xEF,0xF6,0x00,0xF1,0xF5,0x00,0xF2,0xF4,0x00,0xF5,0xF3,0x00,0xF6,0xF2,0x00,0xF7,0xF2,0x00,0xFA,0xF0,0x00,0xFA,0xEF,0x00,0xFC,0xEE,0x00,0xFD,0xEC,0x00,0xFF,0xEB,0x00,0xFF,0xE9,0x00,0xFF,0xE8,0x00,0xFF,0xE7,0x00,0xFF,0xE6,0x00,0xFF,0xE3,0x00,0xFF,0xE3,0x00,0xFF,0xE1,0x00,0xFF,0xDF,0x00,0xFF,0xDE,0x00,0xFF,0xDC,0x00,0xFF,0xDA,0x00,0xFF,0xD8,0x00,0xFF,0xD6,0x00,0xFF,0xD4,0x00,0xFF,0xD2,0x00,0xFF,0xD0,0x00,0xFF,0xCF,0x00,0xFF,0xCC,0x00,0xFF,0xCA,0x00,0xFF,0xC8,0x00,0xFF,0xC5,0x00,0xFF,0xC3,0x00,0xFF,0xC1,0x00,0xFF,0xBF,0x00,0xFF,0xBD,0x00,0xFF,0xBB,0x00,0xFF,0xB9,0x00,0xFF,0xB5,0x00,0xFF,0xB3,0x00,0xFF,0xB1,0x00,0xFF,0xAF,0x00,0xFF,0xAC,0x00,0xFF,0xAA,0x00,0xFF,0xA8,0x00,0xFF,0xA5,0x00,0xFF,0xA3,0x00,0xFF,0xA1,0x00,0xFF,0x9F,0x00,0xFF,0x9C,0x00,0xFF,0x99,0x00,0xFF,0x97,0x00,0xFF,0x95,0x00,0xFF,0x93,0x00,0xFF,0x90,0x00,0xFF,0x8F,0x00,0xFF,0x8C,0x00,0xFF,0x8A,0x00,0xFF,0x88,0x00,0xFF,0x86,0x00,0xFF,0x83,0x00,0xFF,0x81,0x00,0xFF,0x7F,0x00,0xFF,0x7D,0x00,0xFF,0x7C,0x00,0xFF,0x7A,0x00,0xFF,0x78,0x00,0xFF,0x76,0x00,0xFF,0x74,0x00,0xFF,0x72,0x00,0xFF,0x71,0x00,0xFF,0x6F,0x00,0xFF,0x6D,0x00,0xFF,0x6A,0x00,0xFF,0x69,0x00,0xFF,0x67,0x00,0xFF,0x65,0x00,0xFF,0x64,0x00,0xFF,0x61,0x00,0xFF,0x5F,0x00,0xFF,0x5D,0x00,0xFF,0x5B,0x00,0xFF,0x5A,0x00,0xFF,0x57,0x00,0xFF,0x56,0x00,0xFF,0x54,0x00,0xFF,0x51,0x00,0xFF,0x4F,0x00,0xFF,0x4E,0x00,0xFF,0x4C,0x00,0xFF,0x4A,0x00,0xFF,0x48,0x00,0xFF,0x46,0x00,0xFF,0x45,0x00,0xFF,0x43,0x00,0xFF,0x40,0x00,0xFF,0x3F,0x00,0xFF,0x3C,0x00,0xFF,0x3B,0x00,0xFF,0x39,0x00,0xFF,0x37,0x00,0xFF,0x35,0x00,0xFF,0x33,0x00,0xFF,0x32,0x00,0xFF,0x30,0x00,0xFF,0x2F,0x00,0xFF,0x2D,0x00,0xFF,0x2B,0x00,0xFF,0x2A,0x00,0xFF,0x28,0x00,0xFF,0x27,0x00,0xFF,0x25,0x00,0xFF,0x23,0x00,0xFF,0x22,0x00,0xFF,0x21,0x00,0xFF,0x1F,0x00,0xFF,0x1E,0x00,0xFF,0x1C,0x00,0xFF,0x1B,0x00,0xFF,0x1A,0x00,0xFF,0x19,0x00,0xFF,0x18,0x00,0xFF,0x16,0x00,0xFF,0x16,0x01,0xFF,0x15,0x02,0xFF,0x14,0x02,0xFF,0x12,0x02,0xFF,0x12,0x03,0xFF,0x12,0x04,0xFF,0x10,0x05,0xFF,0x10,0x06,0xFF,0x0F,0x06,0xFF,0x0F,0x07,0xFF,0x0D,0x08,0xFF,0x0D,0x09,0xFF,0x0C,0x0A,0xFF,0x0C,0x0B,0xFF,0x0C,0x0C,0xFF,0x0B,0x0C,0xFF,0x0B,0x0E,0xFF,0x0A,0x0F,0xFF,0x09,0x10,0xFF,0x09,0x11,0xFF,0x08,0x12,0xFF,0x08,0x13,0xFF,0x08,0x14,0xFF,0x07,0x15,0xFF,0x07,0x16,0xFF,0x06,0x18,0xFF,0x06,0x19,0xFF,0x06,0x1A,0xFF,0x06,0x1C,0xFF,0x06,0x1D,0xFF,0x06,0x1E,0xFF,0x05,0x1F,0xFF,0x05,0x20,0xFF,0x05,0x21,0xFF,0x05,0x23,0xFF,0x04,0x24,0xFF,0x04,0x25,0xFF,0x04,0x26,0xFF,0x04,0x28,0xFF,0x03,0x29,0xFF,0x03,0x2B,0xFF,0x03,0x2B,0xFF,0x03,0x2D,0xFF,0x03,0x2E,0xFF,0x03,0x30,0xFF,0x03,0x31,0xFF,0x02,0x32,0xFF,0x03,0x34,0xFF,0x03,0x35,0xFF,0x02,0x37,0xFF,0x03,0x39,0xFF,0x02,0x3A,0xFF,0x02,0x3B,0xFF,0x01,0x3C,0xFF,0x01,0x3E,0xFF,0x01,0x3F,0xFF,0x01,0x40,0xFF,0x02,0x42,0xFF,0x02,0x44,0xFF,0x01,0x45,0xFF,0x01,0x46,0xFF,0x01,0x48,0xFF,0x01,0x49,0xFF,0x01,0x4A,0xFF,0x01,0x4C,0xFF,0x00,0x4E,0xFF,0x01,0x4E,0xFF,0x00,0x50,0xFF,0x01,0x52,0xFF,0x01,0x52,0xFF,0x00,0x54,0xFF,0x00,0x55,0xFF,0x00,0x56,0xFF,0x00,0x58,0xFF,0x00,0x58,0xFF,0x00,0x59,0xFF,0x00,0x5A,0xFF,0x00,0x5B,0xFF,0x00,0x5C,0xFF,0x00,0x5D,0xFF,0x00,0x5E,0xFF,0x00,0x5F,0xFF,0x00,0x60,0xFF,0x00,0x61,0xFF,0x00,0x62,0xFF,0x00,0x63,0xFF,0x00,0x64,0xFF,0x00,0x65,0xFF,0x00,0x66,0xFF,0x00,0x67,0xFF,0x00,0x69,0xFF,0x00,0x6A,0xFF,0x00,0x6A,0xFF,0x00,0x6B,0xFF,0x00,0x6C,0xFF,0x00,0x6E,0xFF,0x00,0x6F,0xFF,0x00,0x70,0xFF,0x00,0x71,0xFF,0x00,0x72,0xFF,0x00,0x73,0xFF,0x00,0x74,0xFF,0x00,0x75,0xFF,0x00,0x76,0xFF,0x00,0x77,0xFF,0x00,0x79,0xFF,0x00,0x7A,0xFF,0x00,0x7B,0xFF,0x00,0x7B,0xFF,0x00,0x7D,0xFF,0x00,0x7E,0xFF,0x00,0x7F,0xFF,0x00,0x80,0xFF,0x00,0x82,0xFF,0x00,0x83,0xFF,0x00,0x83,0xFF,0x00,0x84,0xFF,0x00,0x86,0xFF,0x00,0x87,0xFF,0x00,0x88,0xFF,0x00,0x89,0xFF,0x00,0x8A,0xFF,0x00,0x8C,0xFF,0x00,0x8D,0xFF,0x00,0x8E,0xFF,0x00,0x8F,0xFF,0x00,0x90,0xFF,0x00,0x92,0xFF,0x00,0x93,0xFF,0x00,0x93,0xFF,0x00,0x94,0xFF,0x00,0x96,0xFF,0x00,0x97,0xFF,0x00,0x98,0xFF,0x00,0x99,0xFF,0x00,0x9A,0xFF,0x00,0x9B,0xFF,0x00,0x9C,0xFF,0x00,0x9E,0xFF,0x00,0x9E,0xFF,0x00,0x9F,0xFF,0x00,0xA0,0xFF,0x00,0xA1,0xFF,0x00,0xA3,0xFF,0x00,0xA4,0xFF,0x00,0xA4,0xFF,0x00,0xA6,0xFF,0x00,0xA7,0xFF,0x00,0xA7,0xFF,0x00,0xA9,0xFF,0x00,0xAA,0xFF,0x00,0xAB,0xFF,0x00,0xAC,0xFF,0x00,0xAD,0xFF,0x00,0xAE,0xFF,0x00,0xAE,0xFF,0x00,0xB0,0xFF,0x00,0xB1,0xFF,0x00,0xB1,0xFF,0x00,0xB2,0xFF,0x00,0xB3,0xFF,0x00,0xB5,0xFF,0x00,0xB6,0xFF,0x00,0xB7,0xFF,0x00,0xB8,0xFF,0x00,0xB8,0xFF,0x00,0xBA,0xFF,0x00,0xBB,0xFF,0x00,0xBB,0xFF,0x00,0xBC,0xFF,0x00,0xBD,0xFF,0x00,0xBD,0xFF,0x00,0xBE,0xFF,0x00,0xBF,0xFF,0x00,0xC0,0xFE,0x00,0xC1,0xFE,0x00,0xC2,0xFE,0x00,0xC2,0xFF,0x00,0xC3,0xFE,0x00,0xC4,0xFE,0x00,0xC5,0xFE,0x00,0xC6,0xFD,0x00,0xC7,0xFD,0x00,0xC8,0xFD,0x00,0xC8,0xFC,0x00,0xC9,0xFC,0x00,0xCA,0xFC,0x00,0xCB,0xFC,0x00,0xCC,0xFB,0x00,0xCC,0xFC,0x00,0xCD,0xFB,0x00,0xCE,0xFB,0x00,0xCF,0xFB,0x00,0xCF,0xFA,0x00,0xD0,0xFA,0x00,0xD1,0xFA,0x00,0xD1,0xFA,0x00,0xD3,0xF9,0x00,0xD3,0xFA,0x00,0xD4,0xF9,0x00,0xD5,0xF9,0x00,0xD5,0xF8,0x00,0xD6,0xF8,0x00,0xD7,0xF8,0x00,0xD8,0xF7,0x00,0xD9,0xF7,0x00,0xD9,0xF6,0x00,0xDA,0xF7,0x00,0xDB,0xF6,0x00,0xDC,0xF5,0x00,0xDC,0xF5,0x00,0xDD,0xF5,0x00,0xDD,0xF5,0x00,0xDE,0xF5,0x00,0xDF,0xF4,0x00,0xDF,0xF4,0x00,0xE0,0xF3,0x00,0xE1,0xF4,0x00,0xE2,0xF2,0x00,0xE2,0xF3,0x00,0xE3,0xF2,0x00,0xE3,0xF1,0x00,0xE4,0xF1,0x00,0xE5,0xF1,0x00,0xE6,0xF0,0x00,0xE6,0xF0,0x00,0xE7,0xF0,0x00,0xE7,0xEF,0x00,0xE8,0xEF,0x00,0xE9,0xEE,0x00,0xEA,0xEE,0x00,0xEA,0xEE,0x00,0xEB,0xED,0x00,0xEC,0xED,0x00,0xEC,0xED,0x00,0xED,0xEB,0x00,0xED,0xEC,0x00,0xED,0xEB,0x00,0xEE,0xEA,0x00,0xEF,0xEB,0x00,0xF0,0xE9,0x00,0xF0,0xEA,0x00,0xF1,0xE9,0x00,0xF1,0xE8,0x00,0xF2,0xE7,0x00,0xF2,0xE7,0x00,0xF3,0xE6,0x00,0xF3,0xE6,0x00,0xF4,0xE6,0x00,0xF4,0xE5,0x00,0xF5,0xE5,0x00,0xF6,0xE4,0x00,0xF5,0xE3,0x00,0xF7,0xE3,0x00,0xF6,0xE2,0x00,0xF8,0xE1,0x00,0xF8,0xE1,0x00,0xF8,0xE1,0x00,0xF9,0xDF,0x00,0xF9,0xDF,0x00,0xFA,0xDE,0x00,0xFA,0xDE,0x00,0xFA,0xDE,0x00,0xFA,0xDD,0x00,0xFB,0xDC,0x00,0xFC,0xDB,0x00,0xFC,0xDB,0x00,0xFD,0xDB,0x00,0xFD,0xDA,0x00,0xFD,0xD8,0x00,0xFD,0xD8,0x00,0xFE,0xD8,0x00,0xFE,0xD7,0x00,0xFF,0xD6,0x00,0xFE,0xD5,0x00,0xFF,0xD5,0x00,0xFF,0xD3,0x00,0xFF,0xD3,0x00,0xFF,0xD2,0x00,0xFF,0xD2,0x00,0xFF,0xD2,0x00,0xFF,0xD0,0x00,0xFF,0xD0,0x00,0xFF,0xCF,0x00,0xFF,0xCF,0x00,0xFF,0xCE,0x00,0xFF,0xCD,0x00,0xFF,0xCC,0x00,0xFF,0xCC,0x00,0xFF,0xCB,0x00,0xFF,0xCA,0x00,0xFF,0xC9,0x00,0xFF,0xC9,0x00,0xFF,0xC8,0x00,0xFF,0xC7,0x00,0xFF,0xC7,0x00,0xFF,0xC6,0x00,0xFF,0xC5,0x00,0xFF,0xC5,0x00,0xFF,0xC4,0x00,0xFF,0xC3,0x00,0xFF,0xC2,0x00,0xFF,0xC2,0x00,0xFF,0xC1,0x00,0xFF,0xC0,0x00,0xFF,0xBF,0x00,0xFF,0xBE,0x00,0xFF,0xBD,0x00,0xFF,0xBC,0x00,0xFF,0xBC,0x00,0xFF,0xBB,0x00,0xFF,0xBA,0x00,0xFF,0xB9,0x00,0xFF,0xB9,0x00,0xFF,0xB8,0x00,0xFF,0xB6,0x00,0xFF,0xB6,0x00,0xFF,0xB5,0x00,0xFF,0xB4,0x00,0xFF,0xB3,0x00,0xFF,0xB2,0x00,0xFF,0xB1,0x00,0xFF,0xB0,0x00,0xFF,0xB0,0x00,0xFF,0xAF,0x00,0xFF,0xAE,0x00,0xFF,0xAD,0x00,0xFF,0xAC,0x00,0xFF,0xAB,0x00,0xFF,0xAA,0x00,0xFF,0xA9,0x00,0xFF,0xA8,0x00,0xFF,0xA8,0x00,0xFF,0xA6,0x00,0xFF,0xA6,0x00,0xFF,0xA5,0x00,0xFF,0xA4,0x00,0xFF,0xA3,0x00,0xFF,0xA2,0x00,0xFF,0xA1,0x00,0xFF,0xA0,0x00,0xFF,0x9F,0x00,0xFF,0x9E,0x00,0xFF,0x9D,0x00,0xFF,0x9D,0x00,0xFF,0x9B,0x00,0xFF,0x9B,0x00,0xFF,0x99,0x00,0xFF,0x98,0x00,0xFF,0x98,0x00,0xFF,0x97,0x00,0xFF,0x95,0x00,0xFF,0x94,0x00,0xFF,0x93,0x00,0xFF,0x93,0x00,0xFF,0x92,0x00,0xFF,0x91,0x00,0xFF,0x90,0x00,0xFF,0x8F,0x00,0xFF,0x8E,0x00,0xFF,0x8D,0x00,0xFF,0x8C,0x00,0xFF,0x8B,0x00,0xFF,0x8A,0x00,0xFF,0x89,0x00,0xFF,0x89,0x00,0xFF,0x88,0x00,0xFF,0x87,0x00,0xFF,0x86,0x00,0xFF,0x84,0x00,0xFF,0x84,0x00,0xFF,0x82,0x00,0xFF,0x82,0x00,0xFF,0x81,0x00,0xFF,0x80,0x00,0xFF,0x7F,0x00,0xFF,0x7E,0x00,0xFF,0x7D,0x00,0xFF,0x7C,0x00,0xFF,0x7B,0x00,0xFF,0x7B,0x00,0xFF,0x7A,0x00,0xFF,0x78,0x00,0xFF,0x78,0x00,0xFF,0x77,0x00,0xFF,0x76,0x00,0xFF,0x74,0x00,0xFF,0x74,0x00,0xFF,0x73,0x00,0xFF,0x72,0x00,0xFF,0x71,0x00,0xFF,0x70,0x00,0xFF,0x70,0x00,0xFF,0x6E,0x00,0xFF,0x6D,0x00,0xFF,0x6C,0x00,0xFF,0x6C,0x00,0xFF,0x6B,0x00,0xFF,0x6A,0x00,0xFF,0x6A,0x00,0xFF,0x68,0x00,0xFF,0x67,0x00,0xFF,0x66,0x00,0xFF,0x66,0x00,0xFF,0x65,0x00,0xFF,0x64,0x00,0xFF,0x64,0x00,0xFF,0x62,0x00,0xFF,0x62,0x00,0xFF,0x61,0x00,0xFF,0x60,0x00,0xFF,0x5F,0x00,0xFF,0x5E,0x00,0xFF,0x5D,0x00,0xFF,0x5D,0x00,0xFF,0x5C,0x00,0xFF,0x5A,0x00,0xFF,0x5A,0x00,0xFF,0x59,0x00,0xFF,0x58,0x00,0xFF,0x57,0x00,0xFF,0x56,0x00,0xFF,0x55,0x00,0xFF,0x54,0x00,0xFF,0x54,0x00,0xFF,0x53,0x00,0xFF,0x52,0x00,0xFF,0x51,0x00,0xFF,0x50,0x00,0xFF,0x4F,0x00,0xFF,0x4E,0x00,0xFF,0x4D,0x00,0xFF,0x4D,0x00,0xFF,0x4C,0x00,0xFF,0x4A,0x00,0xFF,0x4A,0x00,0xFF,0x48,0x00,0xFF,0x47,0x00,0xFF,0x47,0x00,0xFF,0x45,0x00,0xFF,0x45,0x00,0xFF,0x44,0x00,0xFF,0x43,0x00,0xFF,0x43,0x00,0xFF,0x41,0x00,0xFF,0x40,0x00,0xFF,0x40,0x00,0xFF,0x3F,0x00,0xFF,0x3E,0x00,0xFF,0x3C,0x00,0xFF,0x3C,0x00,0xFF,0x3B,0x00,0xFF,0x3A,0x00,0xFF,0x38,0x00,0xFF,0x38,0x00,0xFF,0x37,0x00,0xFF,0x36,0x00,0xFF,0x35,0x00,0xFF,0x34,0x00,0xFF,0x34,0x00,0xFF,0x33,0x00,0xFF,0x31,0x00,0xFF,0x31,0x00,0xFF,0x2F,0x00,0xFF,0x2F,0x00,0xFF,0x2E,0x00,0xFF,0x2C,0x00,0xFF,0x2C,0x00,0xFF,0x2B,0x00,0xFF,0x2A,0x00,0xFF,0x29,0x00,0xFF,0x28,0x00,0xFF,0x27,0x00,0xFF,0x26,0x00,0xFF,0x26,0x00,0xFF,0x25,0x00,0xFF,0x25,0x00,0xFF,0x23,0x00,0xFF,0x23,0x00,0xFF,0x22,0x00,0xFF,0x21,0x00,0xFF,0x20,0x00,0xFF,0x1F,0x00,0xFF,0x1E,0x00,0xFF,0x1D,0x00,0xFF,0x1D,0x00,0xFF,0x1C,0x00,0xFF,0x1B,0x00,0xFF,0x1A,0x00,0xFF,0x19,0x00,0xFF,0x19,0x00,0xFF,0x18,0x00,0xFF,0x17,0x00,0xFF,0x16,0x00,0xFF,0x15,0x00,0xFF,0x15,0x00,0xFF,0x14,0x00,0xFF,0x14,0x00,0xFF,0x12,0x00,0xFF,0x12,0x00,0xFF,0x12,0x00,0xFF,0x10,0x00,0xFF,0x10,0x00,0xFF,0x0F,0x00,0xFF,0x0E,0x00,0xFF,0x0E,0x00,0xFF,0x0D,0x00,0xFF,0x0C,0x00,0xFF,0x0B,0x00,0xFF,0x0B,0x00,0xFF,0x0B,0x00,0xFF,0x0A,0x00,0xFF,0x09,0x00,0xFF,0x09,0x00,0xFF,0x08,0x00,0xFF,0x07,0x00,0xFF,0x07,0x00,0xFF,0x06,0x00,0xFF,0x06,0x00,0xFF,0x05,0x00,0xFF,0x04,0x00,0xFF,0x04,0x00,0xFF,0x04,0x00,0xFF,0x04,0x00,0xFF,0x03,0x00,0xFF,0x03,0x00,0xFF,0x02,0x00,0xFF,0x01,0x00,0xFF,0x01,0x00,0xFF,0x01,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x01,0xFF,0x00,0x01,0xFF,0x00,0x02,0xFF,0x00,0x01,0xFF,0x00,0x02,0xFF,0x00,0x03,0xFF,0x00,0x03,0xFF,0x00,0x03,0xFF,0x00,0x04,0xFF,0x00,0x05,0xFF,0x00,0x05,0xFF,0x00,0x05,0xFF,0x00,0x06,0xFF,0x00,0x07,0xFF,0x00,0x06,0xFF,0x00,0x07,0xFF,0x00,0x08,0xFF,0x00,0x09,0xFF,0x00,0x09,0xFF,0x00,0x09,0xFF,0x00,0x0B,0xFF,0x00,0x0B,0xFF,0x00,0x0C,0xFF,0x00,0x0B,0xFF,0x00,0x0C,0xFF,0x00,0x0E,0xFF,0x00,0x0D,0xFF,0x00,0x0E,0xFF,0x00,0x0F,0xFF,0x00,0x0F,0xFF,0x00,0x10,0xFF,0x00,0x11,0xFF,0x00,0x11,0xFF,0x00,0x12,0xFF,0x00,0x13,0xFF,0x00,0x14,0xFF,0x00,0x14,0xFF,0x00,0x15,0xFF,0x00,0x16,0xFF,0x00,0x16,0xFF,0x00,0x17,0xFF,0x00,0x17,0xFF,0x00,0x18,0xFF,0x00,0x19,0xFF,0x00,0x1A,0xFF,0x00,0x1A,0xFF,0x00,0x1B,0xFF,0x00,0x1C,0xFF,0x00,0x1D,0xFF,0x00,0x1E,0xFF,0x00,0x1E,0xFF,0x00,0x1F,0xFF,0x00,0x20,0xFF,0x00,0x21,0xFF,0x00,0x22,0xFF,0x00,0x22,0xFF,0x00,0x22,0xFF,0x00,0x24,0xFF,0x00,0x25,0xFF,0x00,0x26,0xFF,0x00,0x26,0xFF,0x00,0x27,0xFF,0x00,0x27,0xFF,0x00,0x28,0xFF,0x00,0x2A,0xFF,0x00,0x2A,0xFF,0x00,0x2B,0xFF,0x00,0x2C,0xFF,0x00,0x2C,0xFF,0x00,0x2E,0xFF,0x00,0x2E,0xFF,0x00,0x2F,0xFF,0x00,0x30,0xFF,0x00,0x31,0xFF,0x00,0x31,0xFF,0x00,0x32,0xFF,0x00,0x33,0xFF,0x00,0x34,0xFF,0x00,0x35,0xFF,0x00,0x36,0xFF,0x00,0x37,0xFF,0x00,0x37,0xFF,0x00,0x39,0xFF,0x00,0x3A,0xFF,0x00,0x3A,0xFF,0x00,0x3B,0xFF,0x00,0x3C,0xFF,0x00,0x3D,0xFF,0x00,0x3E,0xFF,0x00,0x3E,0xFF,0x00,0x3F,0xFF,0x00,0x40,0xFF,0x00,0x41,0xFF,0x00,0x42,0xFF,0x00,0x43,0xFF,0x00,0x43,0xFF,0x00,0x45,0xFF,0x00,0x46,0xFF,0x00,0x46,0xFF,0x00,0x47,0xFF,0x00,0x48,0xFF,0x00,0x49,0xFF,0x00,0x4A,0xFF,0x00,0x4B,0xFF,0x00,0x4C,0xFF,0x00,0x4C,0xFF,0x00,0x4D,0xFF,0x00,0x4E,0xFF,0x00,0x4F,0xFF,0x00,0x50,0xFF,0x00,0x51,0xFF,0x00,0x51,0xFF,0x00,0x52,0xFF,0x00,0x53,0xFF,0x00,0x54,0xFF,0x00,0x54,0xFF,0x00,0x56,0xFF,0x00,0x56,0xFF,0x00,0x57,0xFF,0x00,0x59,0xFF,0x00,0x59,0xFF,0x00,0x5A,0xFF,0x00,0x5A,0xFF,0x00,0x5C,0xFF,0x00,0x5D,0xFF,0x00,0x5D,0xFF,0x00,0x5E,0xFF,0x00,0x5F,0xFF,0x00,0x60,0xFF,0x00,0x61,0xFF,0x00,0x61,0xFF,0x00,0x62,0xFF,0x00,0x63,0xFF,0x00,0x64,0xFF,0x00,0x64,0xFF,0x00,0x65,0xFF,0x00,0x66,0xFF,0x00,0x67,0xFF,0x00,0x67,0xFF,0x00,0x68,0xFF,0x00,0x69,0xFF,0x00,0x6A,0xFF,0x00,0x6B,0xFF,0x00,0x6B,0xFF,0x00,0x6C,0xFF,0x00,0x6C,0xFF,0x00,0x6D,0xFF,0x00,0x6E,0xFF,0x00,0x6F,0xFF,0x00,0x6F,0xFF,0x00,0x70,0xFF,0x00,0x71,0xFF,0x00,0x72,0xFF,0x00,0x72,0xFF,0x00,0x73,0xFF,0x00,0x74,0xFF,0x00,0x74,0xFF,0x00,0x75,0xFF,0x00,0x76,0xFF,0x00,0x77,0xFF,0x00,0x78,0xFF,0x00,0x78,0xFF,0x00,0x79,0xFF,0x00,0x7A,0xFF,0x00,0x7A,0xFF,0x00,0x7B,0xFF,0x00,0x7C,0xFF,0x00,0x7D,0xFF,0x00,0x7E,0xFF,0x00,0x7E,0xFF,0x00,0x80,0xFF,0x00,0x80,0xFF,0x00,0x81,0xFF,0x00,0x82,0xFF,0x00,0x82,0xFF,0x00,0x83,0xFF,0x00,0x84,0xFF,0x00,0x85,0xFF,0x00,0x85,0xFF,0x00,0x87,0xFF,0x00,0x87,0xFF,0x00,0x88,0xFF,0x00,0x89,0xFF,0x00,0x8A,0xFF,0x00,0x8A,0xFF,0x00,0x8B,0xFF,0x00,0x8C,0xFF,0x00,0x8D,0xFF,0x00,0x8E,0xFF,0x00,0x8F,0xFF,0x00,0x90,0xFF,0x00,0x90,0xFF,0x00,0x91,0xFF,0x00,0x92,0xFF,0x00,0x92,0xFF,0x00,0x94,0xFF,0x00,0x94,0xFF,0x00,0x95,0xFF,0x00,0x95,0xFF,0x00,0x97,0xFF,0x00,0x98,0xFF,0x00,0x98,0xFF,0x00,0x99,0xFF,0x00,0x9A,0xFF,0x00,0x9B,0xFF,0x00,0x9B,0xFF,0x00,0x9C,0xFF,0x00,0x9D,0xFF,0x00,0x9E,0xFF,0x00,0x9F,0xFF,0x00,0x9F,0xFF,0x00,0xA0,0xFF,0x00,0xA1,0xFF,0x00,0xA2,0xFF,0x00,0xA2,0xFF,0x00,0xA3,0xFF,0x00,0xA4,0xFF,0x00,0xA5,0xFF,0x00,0xA6,0xFF,0x00,0xA6,0xFF,0x00,0xA7,0xFF,0x00,0xA8,0xFF,0x00,0xA9,0xFF,0x00,0xAA,0xFF,0x00,0xAA,0xFF,0x00,0xAB,0xFF,0x00,0xAC,0xFF,0x00,0xAD,0xFF,0x00,0xAE,0xFF,0x00,0xAE,0xFF,0x00,0xAF,0xFF,0x00,0xB0,0xFF,0x00,0xB1,0xFF,0x00,0xB1,0xFF,0x00,0xB2,0xFF,0x00,0xB3,0xFF,0x00,0xB4,0xFF,0x00,0xB4,0xFF,0x00,0xB5,0xFF,0x00,0xB6,0xFF,0x00,0xB7,0xFF,0x00,0xB7,0xFF,0x00,0xB8,0xFF,0x00,0xB9,0xFF,0x00,0xB9,0xFF,0x00,0xBA,0xFF,0x00,0xBA,0xFF,0x00,0xBC,0xFF,0x00,0xBC,0xFF,0x00,0xBC,0xFF,0x00,0xBD,0xFF,0x00,0xBE,0xFF,0x00,0xBE,0xFF,0x00,0xBF,0xFF,0x00,0xC0,0xFF,0x00,0xC1,0xFF,0x00,0xC1,0xFF,0x00,0xC1,0xFF,0x00,0xC2,0xFF,0x00,0xC2,0xFF,0x00,0xC4,0xFF,0x00,0xC4,0xFF,0x00,0xC5,0xFF,0x00,0xC5,0xFF,0x00,0xC6,0xFF,0x00,0xC7,0xFF,0x00,0xC7,0xFF,0x00,0xC7,0xFF,0x00,0xC8,0xFF,0x00,0xC9,0xFF,0x00,0xC9,0xFF,0x00,0xCA,0xFF,0x00,0xCA,0xFF,0x00,0xCB,0xFF,0x00,0xCC,0xFF,0x00,0xCC,0xFF,0x00,0xCC,0xFF,0x00,0xCD,0xFF,0x00,0xCD,0xFF,0x00,0xCE,0xFF,0x00,0xCE,0xFF,0x00,0xCF,0xFF,0x00,0xCF,0xFF,0x00,0xD0,0xFF,0x00,0xD0,0xFF,0x00,0xD1,0xFF,0x00,0xD1,0xFF,0x00,0xD1,0xFF,0x00,0xD2,0xFF,0x00,0xD2,0xFF,0x00,0xD3,0xFF,0x00,0xD3,0xFF,0x00,0xD4,0xFF,0x00,0xD3,0xFF,0x00,0xD4,0xFF,0x00,0xD4}; //1024 Pixels //static char plasma_data[] = {0x00,0x00,0x00,0x03,0x00,0x00,0x05,0x00,0x00,0x09,0x00,0x00,0x0E,0x00,0x00,0x12,0x00,0x00,0x17,0x00,0x00,0x1C,0x00,0x00,0x22,0x00,0x00,0x27,0x00,0x00,0x2C,0x00,0x00,0x32,0x00,0x00,0x37,0x00,0x00,0x3C,0x00,0x00,0x41,0x00,0x00,0x45,0x00,0x00,0x4A,0x00,0x00,0x4D,0x00,0x00,0x51,0x00,0x00,0x53,0x00,0x00,0x55,0x00,0x00,0x55,0x00,0x02,0x55,0x02,0x03,0x55,0x03,0x06,0x55,0x03,0x07,0x55,0x05,0x09,0x55,0x06,0x0C,0x55,0x06,0x0F,0x55,0x07,0x10,0x55,0x09,0x13,0x55,0x0A,0x16,0x55,0x0C,0x1A,0x55,0x0C,0x1D,0x54,0x0E,0x20,0x53,0x10,0x23,0x54,0x11,0x26,0x53,0x13,0x2A,0x52,0x14,0x2E,0x51,0x15,0x31,0x50,0x17,0x35,0x50,0x19,0x38,0x4E,0x1A,0x3D,0x4D,0x1C,0x40,0x4D,0x1D,0x44,0x4C,0x1F,0x47,0x4B,0x21,0x4C,0x4A,0x23,0x4F,0x49,0x24,0x54,0x48,0x25,0x57,0x47,0x28,0x5B,0x46,0x29,0x5F,0x45,0x2B,0x62,0x44,0x2D,0x66,0x44,0x2E,0x6A,0x43,0x30,0x6E,0x42,0x32,0x72,0x41,0x33,0x76,0x40,0x35,0x79,0x3F,0x38,0x7C,0x3F,0x39,0x7F,0x3E,0x3B,0x83,0x3D,0x3D,0x86,0x3C,0x3F,0x8A,0x3B,0x40,0x8C,0x3B,0x43,0x8F,0x3B,0x44,0x92,0x3A,0x46,0x95,0x39,0x48,0x98,0x39,0x4A,0x9B,0x39,0x4C,0x9C,0x39,0x4E,0x9F,0x3A,0x4F,0xA1,0x39,0x51,0xA3,0x39,0x52,0xA4,0x39,0x54,0xA6,0x39,0x56,0xA7,0x39,0x57,0xA8,0x39,0x58,0xA8,0x3A,0x5A,0xA9,0x3A,0x5C,0xA8,0x3A,0x5D,0xA8,0x3B,0x5F,0xA8,0x3C,0x61,0xA8,0x3D,0x62,0xA8,0x3D,0x64,0xA9,0x3E,0x66,0xA8,0x3E,0x67,0xA9,0x3F,0x68,0xA8,0x40,0x6A,0xA8,0x41,0x6C,0xA8,0x42,0x6E,0xA8,0x42,0x70,0xA8,0x43,0x71,0xA8,0x44,0x73,0xA8,0x45,0x74,0xA9,0x46,0x76,0xA8,0x48,0x79,0xA8,0x49,0x7A,0xA7,0x4A,0x7C,0xA6,0x4A,0x7D,0xA5,0x4C,0x7F,0xA4,0x4D,0x81,0xA3,0x4E,0x83,0xA2,0x4E,0x85,0xA1,0x50,0x86,0xA0,0x51,0x88,0x9F,0x52,0x8A,0x9D,0x53,0x8B,0x9D,0x55,0x8D,0x9B,0x56,0x8F,0x9A,0x57,0x91,0x98,0x58,0x92,0x98,0x5A,0x94,0x97,0x5B,0x96,0x95,0x5C,0x97,0x94,0x5E,0x99,0x93,0x5F,0x9A,0x91,0x60,0x9C,0x90,0x61,0x9D,0x90,0x62,0x9F,0x8E,0x64,0xA1,0x8D,0x65,0xA2,0x8C,0x67,0xA3,0x8B,0x68,0xA5,0x8A,0x6A,0xA6,0x89,0x6A,0xA7,0x88,0x6B,0xA9,0x87,0x6D,0xAB,0x86,0x6E,0xAB,0x86,0x6F,0xAE,0x85,0x71,0xAE,0x85,0x72,0xAF,0x85,0x73,0xB0,0x84,0x75,0xB2,0x83,0x75,0xB2,0x83,0x77,0xB4,0x83,0x77,0xB5,0x83,0x79,0xB6,0x83,0x7A,0xB6,0x83,0x7B,0xB8,0x83,0x7D,0xB9,0x84,0x7E,0xB9,0x83,0x7F,0xBA,0x84,0x7F,0xBB,0x85,0x82,0xBC,0x85,0x83,0xBD,0x86,0x84,0xBD,0x87,0x85,0xBD,0x87,0x86,0xBE,0x88,0x88,0xBF,0x88,0x89,0xBF,0x89,0x8A,0xC0,0x8B,0x8B,0xC0,0x8C,0x8D,0xC1,0x8D,0x8F,0xC1,0x8E,0x90,0xC2,0x8F,0x91,0xC1,0x90,0x92,0xC2,0x91,0x94,0xC3,0x93,0x95,0xC3,0x93,0x97,0xC3,0x95,0x98,0xC3,0x96,0x99,0xC3,0x98,0x9B,0xC4,0x99,0x9C,0xC3,0x9A,0x9E,0xC4,0x9B,0x9F,0xC4,0x9D,0xA0,0xC4,0x9E,0xA2,0xC4,0x9F,0xA4,0xC4,0xA0,0xA5,0xC4,0xA2,0xA6,0xC4,0xA4,0xA8,0xC4,0xA5,0xA9,0xC5,0xA6,0xAA,0xC5,0xA8,0xAB,0xC4,0xA9,0xAC,0xC4,0xAA,0xAE,0xC4,0xAC,0xAF,0xC4,0xAD,0xB0,0xC4,0xAE,0xB2,0xC4,0xB0,0xB3,0xC4,0xB1,0xB4,0xC4,0xB3,0xB5,0xC5,0xB4,0xB6,0xC4,0xB6,0xB7,0xC4,0xB7,0xB8,0xC4,0xB7,0xBA,0xC4,0xB9,0xBA,0xC4,0xBA,0xBC,0xC4,0xBB,0xBC,0xC4,0xBC,0xBE,0xC4,0xBD,0xBF,0xC4,0xBE,0xBF,0xC4,0xBF,0xC0,0xC4,0xC0,0xC1,0xC4,0xC1,0xC2,0xC4,0xC2,0xC2,0xC4,0xC3,0xC4,0xC4,0xC3,0xC4,0xC4,0xC4}; //200 Pixels static char hflm_data[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x02,0x01,0x01,0x02,0x02,0x01,0x04,0x02,0x01,0x04,0x02,0x03,0x05,0x03,0x03,0x07,0x04,0x04,0x08,0x04,0x03,0x09,0x04,0x04,0x0B,0x05,0x04,0x0C,0x05,0x05,0x0D,0x06,0x05,0x0E,0x07,0x06,0x10,0x07,0x07,0x11,0x08,0x07,0x12,0x09,0x08,0x14,0x09,0x08,0x15,0x0A,0x09,0x17,0x0A,0x09,0x19,0x0B,0x0A,0x1A,0x0C,0x0A,0x1C,0x0D,0x0B,0x1D,0x0D,0x0B,0x1F,0x0D,0x0C,0x22,0x0F,0x0D,0x23,0x0F,0x0E,0x25,0x10,0x0E,0x26,0x11,0x0F,0x28,0x12,0x10,0x2A,0x13,0x10,0x2C,0x13,0x11,0x2E,0x14,0x12,0x2F,0x15,0x12,0x31,0x15,0x13,0x33,0x16,0x14,0x35,0x17,0x15,0x36,0x18,0x15,0x39,0x19,0x16,0x3B,0x19,0x17,0x3D,0x1B,0x17,0x3E,0x1B,0x18,0x40,0x1C,0x19,0x42,0x1D,0x1A,0x43,0x1D,0x1B,0x45,0x1E,0x1C,0x47,0x1F,0x1C,0x49,0x20,0x1D,0x4B,0x21,0x1F,0x4C,0x21,0x1F,0x4E,0x22,0x20,0x50,0x23,0x21,0x52,0x23,0x22,0x53,0x24,0x23,0x55,0x25,0x23,0x56,0x26,0x24,0x59,0x26,0x25,0x5A,0x27,0x26,0x5B,0x28,0x27,0x5D,0x28,0x28,0x5E,0x29,0x29,0x60,0x29,0x2A,0x62,0x2A,0x2B,0x63,0x2B,0x2C,0x64,0x2C,0x2E,0x65,0x2C,0x2E,0x66,0x2C,0x2F,0x68,0x2D,0x31,0x69,0x2E,0x32,0x6A,0x2F,0x32,0x6B,0x2F,0x34,0x6C,0x30,0x34,0x6D,0x30,0x35,0x6F,0x31,0x37,0x70,0x31,0x38,0x71,0x32,0x39,0x72,0x33,0x3B,0x73,0x33,0x3C,0x74,0x34,0x3D,0x75,0x35,0x3E,0x76,0x35,0x3F,0x78,0x36,0x41,0x78,0x36,0x42,0x79,0x36,0x43,0x7A,0x37,0x44,0x7B,0x37,0x46,0x7C,0x38,0x48,0x7D,0x39,0x48,0x7E,0x3A,0x49,0x7F,0x39,0x4B,0x80,0x3A,0x4C,0x81,0x3B,0x4E,0x82,0x3C,0x4F,0x83,0x3C,0x51,0x84,0x3C,0x52,0x84,0x3D,0x54,0x86,0x3E,0x55,0x87,0x3E,0x56,0x88,0x3F,0x57,0x89,0x40,0x59,0x8A,0x40,0x5A,0x8A,0x41,0x5C,0x8B,0x41,0x5D,0x8C,0x42,0x5F,0x8D,0x41,0x60,0x8E,0x42,0x62,0x8E,0x42,0x62,0x8F,0x44,0x65,0x90,0x43,0x65,0x91,0x45,0x67,0x91,0x44,0x69,0x92,0x45,0x6A,0x93,0x46,0x6B,0x94,0x46,0x6C,0x94,0x46,0x6E,0x96,0x47,0x70,0x96,0x48,0x70,0x97,0x48,0x72,0x98,0x48,0x73,0x99,0x49,0x74,0x99,0x49,0x76,0x9A,0x4A,0x77,0x9A,0x4B,0x78,0x9B,0x4B,0x7A,0x9C,0x4B,0x7B,0x9D,0x4B,0x7C,0x9E,0x4C,0x7D,0x9F,0x4C,0x7E,0x9F,0x4D,0x7F,0xA0,0x4E,0x80,0xA0,0x4E,0x82,0xA1,0x4E,0x83,0xA2,0x4F,0x84,0xA3,0x4F,0x85,0xA3,0x4F,0x86,0xA4,0x4F,0x88,0xA5,0x50,0x89,0xA5,0x50,0x89,0xA6,0x51,0x8B,0xA6,0x51,0x8B,0xA7,0x51,0x8D,0xA8,0x51,0x8E,0xA9,0x52,0x8F,0xAA,0x52,0x90,0xAA,0x53,0x92,0xAB,0x53,0x92,0xAB,0x53,0x93,0xAC,0x54,0x95,0xAD,0x53,0x95,0xAE,0x54,0x96,0xAE,0x55,0x98,0xAE,0x54,0x98,0xAF,0x55,0x9A,0xB0,0x56,0x9B,0xB0,0x56,0x9C,0xB1,0x56,0x9D,0xB1,0x56,0x9E,0xB2,0x56,0xA0,0xB3,0x57,0xA0,0xB3,0x57,0xA1,0xB3,0x57,0xA2,0xB4,0x58,0xA3,0xB4,0x58,0xA4,0xB5,0x57,0xA5,0xB6,0x58,0xA6,0xB6,0x58,0xA7,0xB7,0x58,0xA8,0xB7,0x59,0xA9,0xB8,0x58,0xAA,0xB9,0x5A,0xAB,0xB9,0x59,0xAC,0xBA,0x5A,0xAD,0xBA,0x5A,0xAE,0xBB,0x5A,0xAF,0xBB,0x5A,0xB0,0xBC,0x5B,0xB0,0xBC,0x5A,0xB1,0xBD,0x5B,0xB2,0xBD,0x5B,0xB3,0xBD,0x5B,0xB4,0xBE,0x5C,0xB5,0xBE,0x5B,0xB5,0xBE,0x5B,0xB7,0xBF,0x5C,0xB7,0xBF,0x5C,0xB8,0xBF,0x5C,0xB9,0xC0,0x5C,0xB9,0xC0,0x5C,0xBA,0xC0,0x5C,0xBA,0xC1,0x5D,0xBB,0xC2,0x5D,0xBC,0xC2,0x5D,0xBC,0xC2,0x5D,0xBD,0xC2,0x5E,0xBE,0xC3,0x5E,0xBE,0xC3,0x5E,0xBF,0xC3,0x5E,0xC0,0xC3,0x5E,0xC0,0xC4,0x5E,0xC1,0xC4,}; //200 Pixels diff --git a/src/Graphics.cpp b/src/Graphics.cpp deleted file mode 100644 index 5f84088..0000000 --- a/src/Graphics.cpp +++ /dev/null @@ -1,789 +0,0 @@ -#include -#include -#include -#include "Config.h" -#include "Misc.h" -#include "Graphics.h" -#define INCLUDE_FONTDATA -#include "font.h" - -TPT_INLINE void VideoBuffer::BlendPixel(int x, int y, int r, int g, int b, int a) -{ -#ifdef PIX32OGL - pixel t; - if (x<0 || y<0 || x>=Width || y>=Height) - return; - if (a!=255) - { - t = Buffer[y*(Width)+x]; - r = (a*r + (255-a)*PIXR(t)) >> 8; - g = (a*g + (255-a)*PIXG(t)) >> 8; - b = (a*b + (255-a)*PIXB(t)) >> 8; - a = a > PIXA(t) ? a : PIXA(t); - } - Buffer[y*(Width)+x] = PIXRGBA(r,g,b,a); -#else - pixel t; - if (x<0 || y<0 || x>=Width || y>=Height) - return; - if (a!=255) - { - t = Buffer[y*(Width)+x]; - r = (a*r + (255-a)*PIXR(t)) >> 8; - g = (a*g + (255-a)*PIXG(t)) >> 8; - b = (a*b + (255-a)*PIXB(t)) >> 8; - } - Buffer[y*(Width)+x] = PIXRGB(r,g,b); -#endif -} - -TPT_INLINE void VideoBuffer::SetPixel(int x, int y, int r, int g, int b, int a) -{ - if (x<0 || y<0 || x>=Width || y>=Height) - return; -#ifdef PIX32OGL - Buffer[y*(Width)+x] = PIXRGBA(r,g,b,a); -#else - Buffer[y*(Width)+x] = PIXRGB(r,g,b); -#endif -} - -TPT_INLINE void VideoBuffer::AddPixel(int x, int y, int r, int g, int b, int a) -{ - pixel t; - if (x<0 || y<0 || x>=Width || y>=Height) - return; - t = Buffer[y*(Width)+x]; - r = (a*r + 255*PIXR(t)) >> 8; - g = (a*g + 255*PIXG(t)) >> 8; - b = (a*b + 255*PIXB(t)) >> 8; - if (r>255) - r = 255; - if (g>255) - g = 255; - if (b>255) - b = 255; - Buffer[y*(Width)+x] = PIXRGB(r,g,b); -} - -TPT_INLINE int VideoBuffer::SetCharacter(int x, int y, int c, int r, int g, int b, int a) -{ - int i, j, w, bn = 0, ba = 0; - char *rp = font_data + font_ptrs[c]; - w = *(rp++); - for (j=0; j>= 2; - bn -= 2; - } - return x + w; -} - -TPT_INLINE int VideoBuffer::BlendCharacter(int x, int y, int c, int r, int g, int b, int a) -{ - int i, j, w, bn = 0, ba = 0; - char *rp = font_data + font_ptrs[c]; - w = *(rp++); - for (j=0; j>= 2; - bn -= 2; - } - return x + w; -} - -TPT_INLINE int VideoBuffer::AddCharacter(int x, int y, int c, int r, int g, int b, int a) -{ - int i, j, w, bn = 0, ba = 0; - char *rp = font_data + font_ptrs[c]; - w = *(rp++); - for (j=0; j>= 2; - bn -= 2; - } - return x + w; -} - -/** - * Common graphics functions, mostly static methods that provide - * encoding/decoding of different formats and font metrics - */ - -char * Graphics::GenerateGradient(pixel * colours, float * points, int pointcount, int size) -{ - int cp, i, j; - pixel ptemp; - char * newdata = (char*)malloc(size * 3); - float poss, pose, temp; - memset(newdata, 0, size*3); - //Sort the Colours and Points - for (i = (pointcount - 1); i > 0; i--) - { - for (j = 1; j <= i; j++) - { - if (points[j-1] > points[j]) - { - temp = points[j-1]; - points[j-1] = points[j]; - points[j] = temp; - - ptemp = colours[j-1]; - colours[j-1] = colours[j]; - colours[j] = ptemp; - } - } - } - i = 0; - j = 1; - poss = points[i]; - pose = points[j]; - for (cp = 0; cp < size; cp++) - { - float cpos = (float)cp / (float)size, ccpos, cccpos; - if(cpos > pose && j+1 < pointcount) - { - poss = points[++i]; - pose = points[++j]; - } - ccpos = cpos - poss; - cccpos = ccpos / (pose - poss); - if(cccpos > 1.0f) - cccpos = 1.0f; - newdata[(cp*3)] = PIXR(colours[i])*(1.0f-cccpos) + PIXR(colours[j])*(cccpos); - newdata[(cp*3)+1] = PIXG(colours[i])*(1.0f-cccpos) + PIXG(colours[j])*(cccpos); - newdata[(cp*3)+2] = PIXB(colours[i])*(1.0f-cccpos) + PIXB(colours[j])*(cccpos); - } - return newdata; -} - -void *Graphics::ptif_pack(pixel *src, int w, int h, int *result_size){ - int i = 0, datalen = (w*h)*3, cx = 0, cy = 0; - unsigned char *red_chan = (unsigned char*)calloc(1, w*h); - unsigned char *green_chan = (unsigned char*)calloc(1, w*h); - unsigned char *blue_chan = (unsigned char*)calloc(1, w*h); - unsigned char *data = (unsigned char*)malloc(((w*h)*3)+8); - unsigned char *result = (unsigned char*)malloc(((w*h)*3)+8); - - for(cx = 0; cx>8; - result[6] = h; - result[7] = h>>8; - - i -= 8; - - if(BZ2_bzBuffToBuffCompress((char *)(result+8), (unsigned *)&i, (char *)data, datalen, 9, 0, 0) != 0){ - free(data); - free(result); - return NULL; - } - - *result_size = i+8; - free(data); - return result; -} - -pixel *Graphics::ptif_unpack(void *datain, int size, int *w, int *h){ - int width, height, i, cx, cy, resCode; - unsigned char *red_chan; - unsigned char *green_chan; - unsigned char *blue_chan; - unsigned char *data = (unsigned char*)datain; - unsigned char *undata; - pixel *result; - if(size<16){ - printf("Image empty\n"); - return NULL; - } - if(!(data[0]=='P' && data[1]=='T' && data[2]=='i')){ - printf("Image header invalid\n"); - return NULL; - } - width = data[4]|(data[5]<<8); - height = data[6]|(data[7]<<8); - - i = (width*height)*3; - undata = (unsigned char*)calloc(1, (width*height)*3); - red_chan = (unsigned char*)calloc(1, width*height); - green_chan = (unsigned char*)calloc(1, width*height); - blue_chan = (unsigned char *)calloc(1, width*height); - result = (pixel *)calloc(width*height, PIXELSIZE); - - resCode = BZ2_bzBuffToBuffDecompress((char *)undata, (unsigned *)&i, (char *)(data+8), size-8, 0, 0); - if (resCode){ - printf("Decompression failure, %d\n", resCode); - free(red_chan); - free(green_chan); - free(blue_chan); - free(undata); - free(result); - return NULL; - } - if(i != (width*height)*3){ - printf("Result buffer size mismatch, %d != %d\n", i, (width*height)*3); - free(red_chan); - free(green_chan); - free(blue_chan); - free(undata); - free(result); - return NULL; - } - memcpy(red_chan, undata, width*height); - memcpy(green_chan, undata+(width*height), width*height); - memcpy(blue_chan, undata+((width*height)*2), width*height); - - for(cx = 0; cx sw && rh > sh){ - float fx, fy, fyc, fxc; - double intp; - pixel tr, tl, br, bl; - q = (pixel *)malloc(rw*rh*PIXELSIZE); - //Bilinear interpolation for upscaling - for (y=0; y=sw) fxceil = sw-1; - if (fyceil>=sh) fyceil = sh-1; - tr = src[sw*(int)floor(fy)+fxceil]; - tl = src[sw*(int)floor(fy)+(int)floor(fx)]; - br = src[sw*fyceil+fxceil]; - bl = src[sw*fyceil+(int)floor(fx)]; - q[rw*y+x] = PIXRGB( - (int)(((((float)PIXR(tl))*(1.0f-fxc))+(((float)PIXR(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXR(bl))*(1.0f-fxc))+(((float)PIXR(br))*(fxc)))*(fyc)), - (int)(((((float)PIXG(tl))*(1.0f-fxc))+(((float)PIXG(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXG(bl))*(1.0f-fxc))+(((float)PIXG(br))*(fxc)))*(fyc)), - (int)(((((float)PIXB(tl))*(1.0f-fxc))+(((float)PIXB(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXB(bl))*(1.0f-fxc))+(((float)PIXB(br))*(fxc)))*(fyc)) - ); - } - } else { - //Stairstepping - float fx, fy, fyc, fxc; - double intp; - pixel tr, tl, br, bl; - int rrw = rw, rrh = rh; - pixel * oq; - oq = (pixel *)malloc(sw*sh*PIXELSIZE); - memcpy(oq, src, sw*sh*PIXELSIZE); - rw = sw; - rh = sh; - while(rrw != rw && rrh != rh){ - rw *= 0.7; - rh *= 0.7; - if(rw <= rrw || rh <= rrh){ - rw = rrw; - rh = rrh; - } - q = (pixel *)malloc(rw*rh*PIXELSIZE); - //Bilinear interpolation for upscaling - for (y=0; y=sw) fxceil = sw-1; - if (fyceil>=sh) fyceil = sh-1; - tr = oq[sw*(int)floor(fy)+fxceil]; - tl = oq[sw*(int)floor(fy)+(int)floor(fx)]; - br = oq[sw*fyceil+fxceil]; - bl = oq[sw*fyceil+(int)floor(fx)]; - q[rw*y+x] = PIXRGB( - (int)(((((float)PIXR(tl))*(1.0f-fxc))+(((float)PIXR(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXR(bl))*(1.0f-fxc))+(((float)PIXR(br))*(fxc)))*(fyc)), - (int)(((((float)PIXG(tl))*(1.0f-fxc))+(((float)PIXG(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXG(bl))*(1.0f-fxc))+(((float)PIXG(br))*(fxc)))*(fyc)), - (int)(((((float)PIXB(tl))*(1.0f-fxc))+(((float)PIXB(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXB(bl))*(1.0f-fxc))+(((float)PIXB(br))*(fxc)))*(fyc)) - ); - } - free(oq); - oq = q; - sw = rw; - sh = rh; - } - } - return q; -} - -pixel *Graphics::rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f) -{ - int i,j,x,y,w,h,r,g,b,c; - pixel p, *q; - w = (sw+f-1)/f; - h = (sh+f-1)/f; - q = (pixel *)malloc(w*h*PIXELSIZE); - for (y=0; y1) - { - r = (r+c/2)/c; - g = (g+c/2)/c; - b = (b+c/2)/c; - } - q[y*w+x] = PIXRGB(r, g, b); - } - *qw = w; - *qh = h; - return q; -} - -int Graphics::textwidth(const char *s) -{ - int x = 0; - for (; *s; s++) - x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - return x-1; -} - -int Graphics::textnwidth(char *s, int n) -{ - int x = 0; - for (; *s; s++) - { - if (!n) - break; - if(((char)*s)=='\b') - { - if(!s[1]) break; - s++; - continue; - } else if(*s == '\x0F') { - if(!s[1] || !s[2] || !s[3]) break; - s+=3; - continue; - } - x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - n--; - } - return x-1; -} - -void Graphics::textnpos(char *s, int n, int w, int *cx, int *cy) -{ - int x = 0; - int y = 0; - int wordlen, charspace; - while (*s&&n) - { - wordlen = strcspn(s," .,!?\n"); - charspace = textwidthx(s, w-x); - if (charspace=-1; s++) - { - if (!n) { - break; - } - x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x>=w) - { - x = 0; - y += FONT_H+2; - } - n--; - } - } - *cx = x-1; - *cy = y; -} - -int Graphics::textwidthx(char *s, int w) -{ - int x=0,n=0,cw; - for (; *s; s++) - { - if((char)*s == '\b') - { - if(!s[1]) break; - s++; - continue; - } else if (*s == '\x0F') - { - if(!s[1] || !s[2] || !s[3]) break; - s+=3; - continue; - } - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x+(cw/2) >= w) - break; - x += cw; - n++; - } - return n; -} - -int Graphics::PositionAtCharIndex(char *s, int charIndex, int & positionX, int & positionY) -{ - int x = 0, y = 0, lines = 1; - for (; *s; s++) - { - if (!charIndex) - break; - if(*s == '\n') { - lines++; - x = 0; - y += FONT_H+2; - charIndex--; - continue; - } else if(*s =='\b') { - if(!s[1]) break; - s++; - charIndex-=2; - continue; - } else if(*s == '\x0F') { - if(!s[1] || !s[2] || !s[3]) break; - s+=3; - charIndex-=4; - continue; - } - x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - charIndex--; - } - positionX = x; - positionY = y; - return lines; -} - -int Graphics::CharIndexAtPosition(char *s, int positionX, int positionY) -{ - int x=0, y=0,charIndex=0,cw; - for (; *s; s++) - { - if(*s == '\n') { - x = 0; - y += FONT_H+2; - charIndex++; - continue; - } else if(*s == '\b') { - if(!s[1]) break; - s++; - charIndex+=2; - continue; - } else if (*s == '\x0F') { - if(!s[1] || !s[2] || !s[3]) break; - s+=3; - charIndex+=4; - continue; - } - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if ((x+(cw/2) >= positionX && y+FONT_H >= positionY) || y > positionY) - break; - x += cw; - charIndex++; - } - return charIndex; -} - - -int Graphics::textposxy(char *s, int width, int w, int h) -{ - int x=0,y=0,n=0,cw, wordlen, charspace; - while (*s) - { - wordlen = strcspn(s," .,!?\n"); - charspace = textwidthx(s, width-x); - if (charspace=-1; s++) - { - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if ((x+(cw/2) >= w && y+6 >= h)||(y+6 >= h+FONT_H+2)) - return n++; - x += cw; - if (x>=width) { - x = 0; - y += FONT_H+2; - } - n++; - } - } - return n; -} -int Graphics::textwrapheight(char *s, int width) -{ - int x=0, height=FONT_H+2, cw; - int wordlen; - int charspace; - while (*s) - { - wordlen = strcspn(s," .,!?\n"); - charspace = textwidthx(s, width-x); - if (charspace=-1; s++) - { - if (*s == '\n') - { - x = 0; - height += FONT_H+2; - } - else if (*s == '\b') - { - if(!s[1]) break; - s++; - } - else if (*s == '\x0F') - { - if(!s[1] || !s[2] || !s[3]) break; - s+=3; - } - else - { - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x+cw>=width) - { - x = 0; - height += FONT_H+2; - } - x += cw; - } - } - } - return height; -} - -void Graphics::textsize(const char * s, int & width, int & height) -{ - if(!strlen(s)) - { - width = 0; - height = FONT_H; - return; - } - - int cHeight = FONT_H, cWidth = 0, lWidth = 0; - for (; *s; s++) - { - if (*s == '\n') - { - cWidth = 0; - cHeight += FONT_H+2; - } - else if (*s == '\x0F') - { - if(!s[1] || !s[2] || !s[1]) break; - s+=3; - } - else if (*s == '\b') - { - if(!s[1]) break; - s++; - } - else - { - cWidth += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if(cWidth>lWidth) - lWidth = cWidth; - } - } - width = lWidth; - height = cHeight; -} - -void Graphics::draw_icon(int x, int y, Icon icon) -{ - y--; - switch(icon) - { - case IconOpen: - drawchar(x, y, 0x81, 255, 255, 255, 255); - break; - case IconReload: - drawchar(x, y, 0x91, 255, 255, 255, 255); - break; - case IconSave: - drawchar(x, y, 0x82, 255, 255, 255, 255); - break; - case IconVoteUp: - drawchar(x, y, 0xCB, 0, 187, 18, 255); - break; - case IconVoteDown: - drawchar(x, y, 0xCA, 187, 40, 0, 255); - break; - case IconTag: - drawchar(x, y, 0x83, 255, 255, 255, 255); - break; - case IconNew: - drawchar(x, y, 0x92, 255, 255, 255, 255); - break; - case IconLogin: - drawchar(x, y, 0x84, 255, 255, 255, 255); - break; - case IconSimulationSettings: - drawchar(x, y, 0xCF, 255, 255, 255, 255); - break; - case IconRenderSettings: - addchar(x, y, 0xD8, 255, 0, 0, 255); - addchar(x, y, 0xD9, 0, 255, 0, 255); - addchar(x, y, 0xDA, 0, 0, 255, 255); - break; - case IconPause: - drawchar(x, y, 0x90, 255, 255, 255, 255); - break; - case IconFavourite: - drawchar(x, y, 0xCC, 192, 160, 64, 255); - break; - case IconReport: - drawchar(x, y, 0xE3, 255, 255, 0, 255); - break; - case IconUsername: - drawchar(x, y, 0x8B, 32, 64, 128, 255); - drawchar(x, y, 0x8A, 255, 255, 255, 255); - break; - case IconPassword: - drawchar(x, y, 0x8C, 160, 144, 32, 255); - drawchar(x, y, 0x84, 255, 255, 255, 255); - break; - case IconClose: - drawchar(x, y, 0xAA, 230, 230, 230, 255); - break; - case IconVoteSort: - case IconDateSort: - case IconFolder: - case IconSearch: - case IconDelete: - drawchar(x, y, 0x86, 255, 55, 55, 255); - drawchar(x, y, 0x85, 255, 255, 255, 255); - break; - default: - drawchar(x, y, 't', 255, 255, 255, 255); - break; - } -} - -pixel *Graphics::render_packed_rgb(void *image, int width, int height, int cmp_size) -{ - unsigned char *tmp; - pixel *res; - int i; - - tmp = (unsigned char *)malloc(width*height*3); - if (!tmp) - return NULL; - res = (pixel *)malloc(width*height*PIXELSIZE); - if (!res) - { - free(tmp); - return NULL; - } - - i = width*height*3; - if (BZ2_bzBuffToBuffDecompress((char *)tmp, (unsigned *)&i, (char *)image, cmp_size, 0, 0)) - { - free(res); - free(tmp); - return NULL; - } - - for (i=0; i -#include -#include -#if defined(OGLI) -#include "OpenGLHeaders.h" -#endif -#include "Config.h" -//#include "powder.h" - -#ifdef PIX16 -#define PIXELSIZE 2 -#define PIXPACK(x) ((((x)>>8)&0xF800)|(((x)>>5)&0x07E0)|(((x)>>3)&0x001F)) -#define PIXRGB(r,g,b) ((((r)<<8)&0xF800)|(((g)<<3)&0x07E0)|(((b)>>3)&0x001F)) -#define PIXR(x) (((x)>>8)&0xF8) -#define PIXG(x) (((x)>>3)&0xFC) -#define PIXB(x) (((x)<<3)&0xF8) -#else -#define PIXELSIZE 4 -#ifdef PIX32BGR -#define PIXPACK(x) ((((x)>>16)&0x0000FF)|((x)&0x00FF00)|(((x)<<16)&0xFF0000)) -#define PIXRGB(r,g,b) (((b)<<16)|((g)<<8)|((r)))// (((b)<<16)|((g)<<8)|(r)) -#define PIXR(x) ((x)&0xFF) -#define PIXG(x) (((x)>>8)&0xFF) -#define PIXB(x) ((x)>>16) -#else -#ifdef PIX32BGRA -#define PIXPACK(x) ((((x)>>8)&0x0000FF00)|(((x)<<8)&0x00FF0000)|(((x)<<24)&0xFF000000)) -#define PIXRGB(r,g,b) (((b)<<24)|((g)<<16)|((r)<<8)) -#define PIXR(x) (((x)>>8)&0xFF) -#define PIXG(x) (((x)>>16)&0xFF) -#define PIXB(x) (((x)>>24)) -#elif defined(PIX32OGL) -#define PIXPACK(x) (0xFF000000|((x)&0xFFFFFF)) -#define PIXRGB(r,g,b) (0xFF000000|((r)<<16)|((g)<<8)|((b)))// (((b)<<16)|((g)<<8)|(r)) -#define PIXRGBA(r,g,b,a) (((a)<<24)|((r)<<16)|((g)<<8)|((b)))// (((b)<<16)|((g)<<8)|(r)) -#define PIXA(x) (((x)>>24)&0xFF) -#define PIXR(x) (((x)>>16)&0xFF) -#define PIXG(x) (((x)>>8)&0xFF) -#define PIXB(x) ((x)&0xFF) -#else -#define PIXPACK(x) (x) -#define PIXRGB(r,g,b) (((r)<<16)|((g)<<8)|(b)) -#define PIXR(x) ((x)>>16) -#define PIXG(x) (((x)>>8)&0xFF) -#define PIXB(x) ((x)&0xFF) -#endif -#endif -#endif - -#ifdef PIX16 -typedef unsigned short pixel; -#else -typedef unsigned int pixel; -#endif - -//Icon names, see Graphics::draw_icon -enum Icon -{ - NoIcon = 0, - IconOpen, - IconReload, - IconSave, - IconVoteUp, - IconVoteDown, - IconTag, - IconNew, - IconLogin, - IconRenderSettings, - IconSimulationSettings, - IconPause, - IconVoteSort, - IconDateSort, - IconFavourite, - IconFolder, - IconSearch, - IconDelete, - IconReport, - IconUsername, - IconPassword, - IconClose -}; - -//"Graphics lite" - slightly lower performance due to variable size, -class VideoBuffer -{ -public: - pixel * Buffer; - int Width, Height; - - VideoBuffer(int width, int height): Width(width), Height(height), Buffer((pixel*)calloc(width*height, PIXELSIZE)) { }; - void BlendPixel(int x, int y, int r, int g, int b, int a); - void AddPixel(int x, int y, int r, int g, int b, int a); - void SetPixel(int x, int y, int r, int g, int b, int a); - int BlendCharacter(int x, int y, int c, int r, int g, int b, int a); - int AddCharacter(int x, int y, int c, int r, int g, int b, int a); - int SetCharacter(int x, int y, int c, int r, int g, int b, int a); - ~VideoBuffer() { free(Buffer); }; -}; - -class Graphics -{ -public: - pixel *vid; - int sdl_scale; -#ifdef OGLI - //OpenGL specific instance variables - GLuint vidBuf, textTexture; - void Reset(); - #endif - - //Common graphics methods in Graphics.cpp - static char * GenerateGradient(pixel * colours, float * points, int pointcount, int size); - - //PTIF methods - static void *ptif_pack(pixel *src, int w, int h, int *result_size); - static pixel *ptif_unpack(void *datain, int size, int *w, int *h); - static pixel *resample_img_nn(pixel *src, int sw, int sh, int rw, int rh); - static pixel *resample_img(pixel *src, int sw, int sh, int rw, int rh); - static pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f); - static pixel *render_packed_rgb(void *image, int width, int height, int cmp_size); - - //Font/text metrics - static int CharIndexAtPosition(char *s, int positionX, int positionY); - static int PositionAtCharIndex(char *s, int charIndex, int & positionX, int & positionY); - static int textnwidth(char *s, int n); - static void textnpos(char *s, int n, int w, int *cx, int *cy); - static int textwidthx(char *s, int w); - static int textposxy(char *s, int width, int w, int h); - static int textwrapheight(char *s, int width); - static int textwidth(const char *s); - static void textsize(const char * s, int & width, int & height); - - void blendpixel(int x, int y, int r, int g, int b, int a); - void addpixel(int x, int y, int r, int g, int b, int a); - - void draw_icon(int x, int y, Icon icon); - - void Clear(); - void Finalise(); - // - int drawtext(int x, int y, const char *s, int r, int g, int b, int a); - int drawtext(int x, int y, std::string s, int r, int g, int b, int a); - int drawchar(int x, int y, int c, int r, int g, int b, int a); - int addchar(int x, int y, int c, int r, int g, int b, int a); - - void xor_pixel(int x, int y); - void xor_line(int x, int y, int x2, int y2); - void xor_rect(int x, int y, int width, int height); - void xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h); - - void draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a); - void drawrect(int x, int y, int width, int height, int r, int g, int b, int a); - void fillrect(int x, int y, int width, int height, int r, int g, int b, int a); - void clearrect(int x, int y, int width, int height); - void gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2); - - void draw_image(pixel *img, int x, int y, int w, int h, int a); - - Graphics(); - ~Graphics(); -}; - -#endif diff --git a/src/OpenGLGraphics.cpp b/src/OpenGLGraphics.cpp deleted file mode 100644 index b6f8f2a..0000000 --- a/src/OpenGLGraphics.cpp +++ /dev/null @@ -1,401 +0,0 @@ -#include "Graphics.h" -#include "font.h" - -#ifdef OGLI - -Graphics::Graphics(): -sdl_scale(1) -{ - Reset(); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - //Texture for main UI - glEnable(GL_TEXTURE_2D); - - glGenTextures(1, &vidBuf); - glBindTexture(GL_TEXTURE_2D, vidBuf); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, XRES+BARSIZE, YRES+MENUSIZE, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - - glBindTexture(GL_TEXTURE_2D, 0); - - glGenTextures(1, &textTexture); - glBindTexture(GL_TEXTURE_2D, textTexture); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - glBindTexture(GL_TEXTURE_2D, 0); - - glDisable(GL_TEXTURE_2D); -} - -Graphics::~Graphics() -{ -} - -void Graphics::Reset() -{ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - //glOrtho(0, (XRES+BARSIZE)*sdl_scale, 0, (YRES+MENUSIZE)*sdl_scale, -1, 1); - glOrtho(0, (XRES+BARSIZE)*sdl_scale, (YRES+MENUSIZE)*sdl_scale, 0, -1, 1); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - //glRasterPos2i(0, (YRES+MENUSIZE)); - glRasterPos2i(0, 0); - glPixelZoom(1, 1); -} - -void Graphics::Clear() -{ - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); -} - -void Graphics::Finalise() -{ - glFlush(); -} - -int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a) -{ - if(!strlen(s)) - return 0; - int oR = r, oG = g, oB = b; - int width, height; - Graphics::textsize(s, width, height); - VideoBuffer texture(width, height); - int characterX = 0, characterY = 0; - int startX = characterX; - for (; *s; s++) - { - if (*s == '\n') - { - characterX = startX; - characterY += FONT_H+2; - } - else if (*s == '\x0F') - { - if(!s[1] || !s[2] || !s[3]) break; - r = s[1]; - g = s[2]; - b = s[3]; - s += 3; - } - else if (*s == '\x0E') - { - r = oR; - g = oG; - b = oB; - } - else if (*s == '\b') - { - if(!s[1]) break; - switch (s[1]) - { - case 'w': - r = g = b = 255; - break; - case 'g': - r = g = b = 192; - break; - case 'o': - r = 255; - g = 216; - b = 32; - break; - case 'r': - r = 255; - g = b = 0; - break; - case 'l': - r = 255; - g = b = 75; - break; - case 'b': - r = g = 0; - b = 255; - break; - case 't': - b = 255; - g = 170; - r = 32; - break; - } - s++; - } - else - { - characterX = texture.SetCharacter(characterX, characterY, *(unsigned char *)s, r, g, b, a); - } - } - glEnable(GL_TEXTURE_2D); - - //Generate texture - glBindTexture(GL_TEXTURE_2D, textTexture); - - //Draw texture - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.Width, texture.Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, texture.Buffer); - - //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture.Width, texture.Height, GL_BGRA, GL_UNSIGNED_BYTE, texture.Buffer); - glBegin(GL_QUADS); - glTexCoord2d(0, 0); - glVertex2f(x, y); - glTexCoord2d(1, 0); - glVertex2f(x+texture.Width, y); - glTexCoord2d(1, 1); - glVertex2f(x+texture.Width, y+texture.Height); - glTexCoord2d(0, 1); - glVertex2f(x, y+texture.Height); - glEnd(); - - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - return x; -} - -int Graphics::drawtext(int x, int y, std::string s, int r, int g, int b, int a) -{ - return drawtext(x, y, s.c_str(), r, g, b, a); -} - -TPT_INLINE int Graphics::drawchar(int x, int y, int c, int r, int g, int b, int a) -{ - int i, j, w, bn = 0, ba = 0; - char *rp = font_data + font_ptrs[c]; - w = *(rp++); - VideoBuffer texture(w, 12); - texture.SetCharacter(0, 0, c, r, g, b, a); - - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, textTexture); - - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.Width, texture.Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, texture.Buffer); - glBegin(GL_QUADS); - glTexCoord2d(0, 0); - glVertex2f(x, y); - glTexCoord2d(1, 0); - glVertex2f(x+texture.Width, y); - glTexCoord2d(1, 1); - glVertex2f(x+texture.Width, y+texture.Height); - glTexCoord2d(0, 1); - glVertex2f(x, y+texture.Height); - glEnd(); - - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - return x + w; -} - -TPT_INLINE int Graphics::addchar(int x, int y, int c, int r, int g, int b, int a) -{ - int i, j, w, bn = 0, ba = 0; - char *rp = font_data + font_ptrs[c]; - w = *(rp++); - VideoBuffer texture(w, 12); - texture.AddCharacter(0, 0, c, r, g, b, a); - - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, textTexture); - glBlendFunc(GL_ONE, GL_ONE); - - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.Width, texture.Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, texture.Buffer); - glBegin(GL_QUADS); - glTexCoord2d(0, 0); - glVertex2f(x, y); - glTexCoord2d(1, 0); - glVertex2f(x+texture.Width, y); - glTexCoord2d(1, 1); - glVertex2f(x+texture.Width, y+texture.Height); - glTexCoord2d(0, 1); - glVertex2f(x, y+texture.Height); - glEnd(); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - return x + w; -} - -TPT_INLINE void Graphics::xor_pixel(int x, int y) -{ - //OpenGL doesn't support single pixel manipulation, there are ways around it, but with poor performance -} - -TPT_INLINE void Graphics::blendpixel(int x, int y, int r, int g, int b, int a) -{ - //OpenGL doesn't support single pixel manipulation, there are ways around it, but with poor performance -} - -TPT_INLINE void Graphics::addpixel(int x, int y, int r, int g, int b, int a) -{ - //OpenGL doesn't support single pixel manipulation, there are ways around it, but with poor performance -} - -void Graphics::xor_line(int x, int y, int x2, int y2) -{ - glEnable(GL_COLOR_LOGIC_OP); - //glEnable(GL_LINE_SMOOTH); - glLogicOp(GL_XOR); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glBegin(GL_LINES); - glVertex2i(x, y); - glVertex2i(x2, y2); - glEnd(); - glDisable(GL_COLOR_LOGIC_OP); -} - -void Graphics::xor_rect(int x, int y, int width, int height) -{ - glEnable(GL_COLOR_LOGIC_OP); - //glEnable(GL_LINE_SMOOTH); - glLogicOp(GL_XOR); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glBegin(GL_LINE_STRIP); - glVertex2i(x, y); - glVertex2i(x+width, y); - glVertex2i(x+width, y+height); - glVertex2i(x, y+height); - glVertex2i(x, y); - glEnd(); - glDisable(GL_COLOR_LOGIC_OP); -} - -void Graphics::xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h) -{ - //glEnable(GL_COLOR_LOGIC_OP); - //glLogicOp(GL_XOR); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, textTexture); - - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap); - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - - glBegin(GL_QUADS); - glTexCoord2d(0, 0); - glVertex2f(x, y); - glTexCoord2d(1, 0); - glVertex2f(x+w, y); - glTexCoord2d(1, 1); - glVertex2f(x+w, y+h); - glTexCoord2d(0, 1); - glVertex2f(x, y+h); - glEnd(); - - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - //glDisable(GL_COLOR_LOGIC_OP); -} - -void Graphics::draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a) -{ - a = 255; - glColor4ub(r, g, b, a); - glBegin(GL_LINES); - glVertex2i(x, y); - glVertex2i(x2, y2); - glEnd(); -} - -void Graphics::drawrect(int x, int y, int width, int height, int r, int g, int b, int a) -{ - float fx = float(x)+0.5f; - float fy = float(y)+0.5f; - float fwidth = width-1.0f; - float fheight = height-1.0f; - //x++; - //y++; - //height-=2; - //width-=2; - glColor4ub(r, g, b, a); - glBegin(GL_LINE_STRIP); - glVertex2f(fx, fy); - glVertex2f(fx+fwidth, fy); - glVertex2f(fx+fwidth, fy+fheight); - glVertex2f(fx, fy+fheight); //+1 is a hack to prevent squares from missing their corners, will make smoothed lines look like SHIT - glVertex2f(fx, fy); - glEnd(); -} - -void Graphics::fillrect(int x, int y, int width, int height, int r, int g, int b, int a) -{ - /*x++; - y++; - width-=1; - height-=1;*/ - - glColor4ub(r, g, b, a); - glBegin(GL_QUADS); - glVertex2i(x, y); - glVertex2i(x+width, y); - glVertex2i(x+width, y+height); - glVertex2i(x, y+height); - glEnd(); -} - -void Graphics::gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2) -{ - glBegin(GL_QUADS); - glColor4ub(r, g, b, a); - glVertex2i(x, y); - glColor4ub(r2, g2, b2, a2); - glVertex2i(x+width, y); - glColor4ub(r2, g2, b2, a2); - glVertex2i(x+width, y+height); - glColor4ub(r, g, b, a); - glVertex2i(x, y+height); - glEnd(); -} - -void Graphics::clearrect(int x, int y, int width, int height) -{ - glColor4ub(0, 0, 0, 255); - glBegin(GL_QUADS); - glVertex2i(x, y); - glVertex2i(x+width, y); - glVertex2i(x+width, y+height); - glVertex2i(x, y+height); - glEnd(); -} - -void Graphics::draw_image(pixel *img, int x, int y, int w, int h, int a) -{ - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, textTexture); - - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, img); - glBegin(GL_QUADS); - glTexCoord2d(0, 0); - glVertex2f(x, y); - glTexCoord2d(1, 0); - glVertex2f(x+w, y); - glTexCoord2d(1, 1); - glVertex2f(x+w, y+h); - glTexCoord2d(0, 1); - glVertex2f(x, y+h); - glEnd(); - - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); -} - -#endif diff --git a/src/OpenGLHeaders.h b/src/OpenGLHeaders.h deleted file mode 100644 index 8a83472..0000000 --- a/src/OpenGLHeaders.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifdef MACOSX - -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 -#include -#include -#else -//#include -#include -#include -#define GL_RGBA32F 0x8814 -#endif - -#elif defined(WIN32) - -#include -#include -#include - -#else - -#include -#include -#include -#endif diff --git a/src/PixelMethods.inc b/src/PixelMethods.inc deleted file mode 100644 index 4d85f60..0000000 --- a/src/PixelMethods.inc +++ /dev/null @@ -1,348 +0,0 @@ -#include "font.h" - -int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int b, int a) -{ - if(!strlen(s)) - return 0; - int width, height; - - int oR = r, oG = g, oB = b; - int characterX = x, characterY = y; - int startX = characterX; - for (; *s; s++) - { - if (*s == '\n') - { - characterX = startX; - characterY += FONT_H+2; - } - else if (*s == '\x0F') - { - if(!s[1] || !s[2] || !s[3]) break; - r = s[1]; - g = s[2]; - b = s[3]; - s += 3; - } - else if (*s == '\x0E') - { - r = oR; - g = oG; - b = oB; - } - else if (*s == '\b') - { - if(!s[1]) break; - switch (s[1]) - { - case 'w': - r = g = b = 255; - break; - case 'g': - r = g = b = 192; - break; - case 'o': - r = 255; - g = 216; - b = 32; - break; - case 'r': - r = 255; - g = b = 0; - break; - case 'l': - r = 255; - g = b = 75; - break; - case 'b': - r = g = 0; - b = 255; - break; - case 't': - b = 255; - g = 170; - r = 32; - break; - } - s++; - } - else - { - characterX = drawchar(characterX, characterY, *(unsigned char *)s, r, g, b, a); - } - } - return x; -} - -int PIXELMETHODS_CLASS::drawtext(int x, int y, std::string s, int r, int g, int b, int a) -{ - return drawtext(x, y, s.c_str(), r, g, b, a); -} - -TPT_INLINE int PIXELMETHODS_CLASS::drawchar(int x, int y, int c, int r, int g, int b, int a) -{ - int i, j, w, bn = 0, ba = 0; - char *rp = font_data + font_ptrs[c]; - w = *(rp++); - for (j=0; j>= 2; - bn -= 2; - } - return x + w; -} - -TPT_INLINE int PIXELMETHODS_CLASS::addchar(int x, int y, int c, int r, int g, int b, int a) -{ - int i, j, w, bn = 0, ba = 0; - char *rp = font_data + font_ptrs[c]; - w = *(rp++); - for (j=0; j>= 2; - bn -= 2; - } - return x + w; -} - -TPT_INLINE void PIXELMETHODS_CLASS::xor_pixel(int x, int y) -{ - int c; - if (x<0 || y<0 || x>=XRES || y>=YRES) - return; - c = vid[y*(VIDXRES)+x]; - c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c); - if (c<512) - vid[y*(VIDXRES)+x] = PIXPACK(0xC0C0C0); - else - vid[y*(VIDXRES)+x] = PIXPACK(0x404040); -} - -TPT_INLINE void PIXELMETHODS_CLASS::blendpixel(int x, int y, int r, int g, int b, int a) -{ - pixel t; - if (x<0 || y<0 || x>=VIDXRES || y>=VIDYRES) - return; - if (a!=255) - { - t = vid[y*(VIDXRES)+x]; - r = (a*r + (255-a)*PIXR(t)) >> 8; - g = (a*g + (255-a)*PIXG(t)) >> 8; - b = (a*b + (255-a)*PIXB(t)) >> 8; - } - vid[y*(VIDXRES)+x] = PIXRGB(r,g,b); -} - -TPT_INLINE void PIXELMETHODS_CLASS::addpixel(int x, int y, int r, int g, int b, int a) -{ - pixel t; - if (x<0 || y<0 || x>=VIDXRES || y>=VIDYRES) - return; - t = vid[y*(VIDXRES)+x]; - r = (a*r + 255*PIXR(t)) >> 8; - g = (a*g + 255*PIXG(t)) >> 8; - b = (a*b + 255*PIXB(t)) >> 8; - if (r>255) - r = 255; - if (g>255) - g = 255; - if (b>255) - b = 255; - vid[y*(VIDXRES)+x] = PIXRGB(r,g,b); -} - -void PIXELMETHODS_CLASS::xor_line(int x1, int y1, int x2, int y2) -{ - int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; - float e, de; - if (cp) - { - y = x1; - x1 = y1; - y1 = y; - y = x2; - x2 = y2; - y2 = y; - } - if (x1 > x2) - { - y = x1; - x1 = x2; - x2 = y; - y = y1; - y1 = y2; - y2 = y; - } - dx = x2 - x1; - dy = abs(y2 - y1); - e = 0.0f; - if (dx) - de = dy/(float)dx; - else - de = 0.0f; - y = y1; - sy = (y1= 0.5f) - { - y += sy; - e -= 1.0f; - } - } -} - -void PIXELMETHODS_CLASS::xor_rect(int x, int y, int w, int h) -{ - int i; - for (i=0; iabs(x2-x1), x, y, dx, dy, sy; - float e, de; - if (cp) - { - y = x1; - x1 = y1; - y1 = y; - y = x2; - x2 = y2; - y2 = y; - } - if (x1 > x2) - { - y = x1; - x1 = x2; - x2 = y; - y = y1; - y1 = y2; - y2 = y; - } - dx = x2 - x1; - dy = abs(y2 - y1); - e = 0.0f; - if (dx) - de = dy/(float)dx; - else - de = 0.0f; - y = y1; - sy = (y1= 0.5f) - { - y += sy; - e -= 1.0f; - } - } -} - -void PIXELMETHODS_CLASS::drawrect(int x, int y, int w, int h, int r, int g, int b, int a) -{ - int i; - w--; - h--; - for (i=0; i<=w; i++) - { - blendpixel(x+i, y, r, g, b, a); - blendpixel(x+i, y+h, r, g, b, a); - } - for (i=1; i VIDYRES) h = (VIDYRES)-y; //Adjust height to prevent drawing off the bottom - if(a >= 255) - for (j=0; j #include #include "Config.h" -#include "Graphics.h" +#include "graphics/Graphics.h" #if defined(LIN32) || defined(LIN64) #include "icon.h" #endif diff --git a/src/RasterGraphics.cpp b/src/RasterGraphics.cpp deleted file mode 100644 index a33f771..0000000 --- a/src/RasterGraphics.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "Graphics.h" - -#ifndef OGLI - -Graphics::Graphics(): -sdl_scale(1) -{ - vid = (pixel *)malloc(PIXELSIZE * ((XRES+BARSIZE) * (YRES+MENUSIZE))); - -} - -Graphics::~Graphics() -{ - free(vid); -} - -void Graphics::Clear() -{ - memset(vid, 0, PIXELSIZE * ((XRES+BARSIZE) * (YRES+MENUSIZE))); -} - -void Graphics::Finalise() -{ - -} - -#define VIDXRES XRES+BARSIZE -#define VIDYRES YRES+MENUSIZE -#define PIXELMETHODS_CLASS Graphics -#include "PixelMethods.inc" -#undef VIDYRES -#undef VIDXRES -#undef PIXELMETHODS_CLASS - -#endif diff --git a/src/Renderer.cpp b/src/Renderer.cpp deleted file mode 100644 index a83e41e..0000000 --- a/src/Renderer.cpp +++ /dev/null @@ -1,2202 +0,0 @@ -/* - * Renderer.cpp - * - * Created on: Jan 7, 2012 - * Author: Simon - */ -#include -#include -#include -#include -#include -#include "Config.h" -#include "Renderer.h" -#include "Graphics.h" -#include "simulation/Elements.h" -#include "simulation/ElementGraphics.h" -#include "simulation/Air.h" -extern "C" -{ -#include "hmap.h" -#ifdef OGLR -#include "Shaders.h" -#endif -} - -#ifndef OGLI -#define VIDXRES XRES+BARSIZE -#define VIDYRES YRES+MENUSIZE -#else -#define VIDXRES XRES -#define VIDYRES YRES -#endif - -#ifdef OGLR -#define drawrect(args) g->drawrect(args) -#endif - -void Renderer::clearScreen(float alpha) -{ -#ifdef OGLR - GLint prevFbo; - if(alpha > 0.999f) - { - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); - glClear(GL_COLOR_BUFFER_BIT); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); - } - else - { - glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); - glColor4f(1.0f, 1.0f, 1.0f, alpha); - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); - glBegin(GL_QUADS); - glVertex2f(0, 0); - glVertex2f(XRES, 0); - glVertex2f(XRES, YRES); - glVertex2f(0, YRES); - glEnd(); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); - glBlendEquation(GL_FUNC_ADD); - } - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); -#endif -#ifdef OGLI - std::fill(vid, vid+(VIDXRES*VIDYRES), 0); -#endif -} -#ifdef OGLR -void Renderer::checkShader(GLuint shader, char * shname) -{ - GLint status; - glGetShaderiv(shader, GL_COMPILE_STATUS, &status); - if (status == GL_FALSE) - { - char errorBuf[ GL_INFO_LOG_LENGTH]; - int errLen; - glGetShaderInfoLog(shader, GL_INFO_LOG_LENGTH, &errLen, errorBuf); - fprintf(stderr, "Failed to compile %s shader:\n%s\n", shname, errorBuf); - exit(1); - } -} -void Renderer::checkProgram(GLuint program, char * progname) -{ - GLint status; - glGetProgramiv(program, GL_LINK_STATUS, &status); - if (status == GL_FALSE) - { - char errorBuf[ GL_INFO_LOG_LENGTH]; - int errLen; - glGetShaderInfoLog(program, GL_INFO_LOG_LENGTH, &errLen, errorBuf); - fprintf(stderr, "Failed to link %s program:\n%s\n", progname, errorBuf); - exit(1); - } -} -void Renderer::loadShaders() -{ - GLuint vertexShader, fragmentShader; - - //Particle texture - vertexShader = glCreateShader(GL_VERTEX_SHADER); - fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); - - glShaderSource( vertexShader, 1, &fireVertex, NULL); - glShaderSource( fragmentShader, 1, &fireFragment, NULL); - - glCompileShader( vertexShader ); - checkShader(vertexShader, "FV"); - glCompileShader( fragmentShader ); - checkShader(fragmentShader, "FF"); - - fireProg = glCreateProgram(); - glAttachShader( fireProg, vertexShader ); - glAttachShader( fireProg, fragmentShader ); - glLinkProgram( fireProg ); - checkProgram(fireProg, "F"); - - //Lensing - vertexShader = glCreateShader(GL_VERTEX_SHADER); - fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); - - glShaderSource( vertexShader, 1, &lensVertex, NULL); - glShaderSource( fragmentShader, 1, &lensFragment, NULL); - - glCompileShader( vertexShader ); - checkShader(vertexShader, "LV"); - glCompileShader( fragmentShader ); - checkShader(fragmentShader, "LF"); - - lensProg = glCreateProgram(); - glAttachShader( lensProg, vertexShader ); - glAttachShader( lensProg, fragmentShader ); - glLinkProgram( lensProg ); - checkProgram(lensProg, "L"); - - //Air Velocity - vertexShader = glCreateShader(GL_VERTEX_SHADER); - fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); - - glShaderSource( vertexShader, 1, &airVVertex, NULL); - glShaderSource( fragmentShader, 1, &airVFragment, NULL); - - glCompileShader( vertexShader ); - checkShader(vertexShader, "AVX"); - glCompileShader( fragmentShader ); - checkShader(fragmentShader, "AVF"); - - airProg_Velocity = glCreateProgram(); - glAttachShader( airProg_Velocity, vertexShader ); - glAttachShader( airProg_Velocity, fragmentShader ); - glLinkProgram( airProg_Velocity ); - checkProgram(airProg_Velocity, "AV"); - - //Air Pressure - vertexShader = glCreateShader(GL_VERTEX_SHADER); - fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); - - glShaderSource( vertexShader, 1, &airPVertex, NULL); - glShaderSource( fragmentShader, 1, &airPFragment, NULL); - - glCompileShader( vertexShader ); - checkShader(vertexShader, "APV"); - glCompileShader( fragmentShader ); - checkShader(fragmentShader, "APF"); - - airProg_Pressure = glCreateProgram(); - glAttachShader( airProg_Pressure, vertexShader ); - glAttachShader( airProg_Pressure, fragmentShader ); - glLinkProgram( airProg_Pressure ); - checkProgram(airProg_Pressure, "AP"); - - //Air cracker - vertexShader = glCreateShader(GL_VERTEX_SHADER); - fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); - - glShaderSource( vertexShader, 1, &airCVertex, NULL); - glShaderSource( fragmentShader, 1, &airCFragment, NULL); - - glCompileShader( vertexShader ); - checkShader(vertexShader, "ACV"); - glCompileShader( fragmentShader ); - checkShader(fragmentShader, "ACF"); - - airProg_Cracker = glCreateProgram(); - glAttachShader( airProg_Cracker, vertexShader ); - glAttachShader( airProg_Cracker, fragmentShader ); - glLinkProgram( airProg_Cracker ); - checkProgram(airProg_Cracker, "AC"); -} -#endif - -void Renderer::FinaliseParts() -{ -#ifdef OGLR - glEnable( GL_TEXTURE_2D ); - if(display_mode & DISPLAY_WARP) - { - float xres = XRES, yres = YRES; - glUseProgram(lensProg); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, partsFboTex); - glUniform1i(glGetUniformLocation(lensProg, "pTex"), 0); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, partsTFX); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_RED, GL_FLOAT, sim->gravx); - glUniform1i(glGetUniformLocation(lensProg, "tfX"), 1); - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, partsTFY); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_GREEN, GL_FLOAT, sim->gravy); - glUniform1i(glGetUniformLocation(lensProg, "tfY"), 2); - glActiveTexture(GL_TEXTURE0); - glUniform1fv(glGetUniformLocation(lensProg, "xres"), 1, &xres); - glUniform1fv(glGetUniformLocation(lensProg, "yres"), 1, &yres); - } - else - { - glBindTexture(GL_TEXTURE_2D, partsFboTex); - glBlendFunc(GL_ONE, GL_ONE); - } - - int sdl_scale = 1; - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glBegin(GL_QUADS); - glTexCoord2d(1, 0); - //glVertex3f(XRES*sdl_scale, (YRES+MENUSIZE)*sdl_scale, 1.0); - glVertex3f(XRES*sdl_scale, YRES*sdl_scale, 1.0); - glTexCoord2d(0, 0); - //glVertex3f(0, (YRES+MENUSIZE)*sdl_scale, 1.0); - glVertex3f(0, YRES*sdl_scale, 1.0); - glTexCoord2d(0, 1); - //glVertex3f(0, MENUSIZE*sdl_scale, 1.0); - glVertex3f(0, 0, 1.0); - glTexCoord2d(1, 1); - //glVertex3f(XRES*sdl_scale, MENUSIZE*sdl_scale, 1.0); - glVertex3f(XRES*sdl_scale, 0, 1.0); - glEnd(); - - if(display_mode & DISPLAY_WARP) - { - glUseProgram(0); - - } - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable( GL_TEXTURE_2D ); -#else - g->draw_image(vid, 0, 0, VIDXRES, VIDYRES, 255); -#endif -} - -void Renderer::RenderZoom() -{ - if(!zoomEnabled) - return; - #ifdef OGLR - int sdl_scale = 1; - int origBlendSrc, origBlendDst; - float zcx1, zcx0, zcy1, zcy0, yfactor, xfactor, i; //X-Factor is shit, btw - xfactor = 1.0f/(float)XRES; - yfactor = 1.0f/(float)YRES; - yfactor*=-1.0f; - - zcx1 = (zoomScopePosition.X)*xfactor; - zcx0 = (zoomScopePosition.X+zoomScopeSize)*xfactor; - zcy1 = (zoomScopePosition.Y-1)*yfactor; - zcy0 = ((zoomScopePosition.Y-1+zoomScopeSize))*yfactor; - - glGetIntegerv(GL_BLEND_SRC, &origBlendSrc); - glGetIntegerv(GL_BLEND_DST, &origBlendDst); - glBlendFunc(GL_ONE, GL_ZERO); - - glEnable( GL_TEXTURE_2D ); - //glReadBuffer(GL_AUX0); - glBindTexture(GL_TEXTURE_2D, partsFboTex); - - //Draw zoomed texture - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glBegin(GL_QUADS); - glTexCoord2d(zcx1, zcy1); - glVertex2i(zoomWindowPosition.X, zoomWindowPosition.Y); - glTexCoord2d(zcx0, zcy1); - glVertex2i(zoomWindowPosition.X+(zoomScopeSize*ZFACTOR), zoomWindowPosition.Y); - glTexCoord2d(zcx0, zcy0); - glVertex2i(zoomWindowPosition.X+(zoomScopeSize*ZFACTOR), zoomWindowPosition.Y+(zoomScopeSize*ZFACTOR)); - glTexCoord2d(zcx1, zcy0); - glVertex2i(zoomWindowPosition.X, zoomWindowPosition.Y+(zoomScopeSize*ZFACTOR)); - glEnd(); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable( GL_TEXTURE_2D ); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - //Lines to make the pixels stand out - glLineWidth(sdl_scale); - //glEnable(GL_LINE_SMOOTH); - glBegin(GL_LINES); - glColor4f(0.0f, 0.0f, 0.0f, 1.0f); - for(i = 0; i < zoomScopeSize; i++) - { - //Across - glVertex2i(zoomWindowPosition.X, zoomWindowPosition.Y+(i*ZFACTOR)); - glVertex2i(zoomWindowPosition.X+(zoomScopeSize*ZFACTOR), zoomWindowPosition.Y+(i*ZFACTOR)); - - //Down - glVertex2i(zoomWindowPosition.X+(i*ZFACTOR), zoomWindowPosition.Y); - glVertex2i(zoomWindowPosition.X+(i*ZFACTOR), zoomWindowPosition.Y+(zoomScopeSize*ZFACTOR)); - } - glEnd(); - - //Draw zoom window border - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glBegin(GL_LINE_LOOP); - glVertex2i(zoomWindowPosition.X, zoomWindowPosition.Y); - glVertex2i(zoomWindowPosition.X+(zoomScopeSize*ZFACTOR), zoomWindowPosition.Y); - glVertex2i(zoomWindowPosition.X+(zoomScopeSize*ZFACTOR), zoomWindowPosition.Y+(zoomScopeSize*ZFACTOR)); - glVertex2i(zoomWindowPosition.X, zoomWindowPosition.Y+(zoomScopeSize*ZFACTOR)); - glEnd(); - //glDisable(GL_LINE_SMOOTH); - - if(zoomEnabled) - { - glEnable(GL_COLOR_LOGIC_OP); - //glEnable(GL_LINE_SMOOTH); - glLogicOp(GL_XOR); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glBegin(GL_LINE_LOOP); - glVertex2i(zoomScopePosition.X, zoomScopePosition.Y); - glVertex2i(zoomScopePosition.X+zoomScopeSize, zoomScopePosition.Y); - glVertex2i(zoomScopePosition.X+zoomScopeSize, zoomScopePosition.Y+zoomScopeSize); - glVertex2i(zoomScopePosition.X, zoomScopePosition.Y+zoomScopeSize); - /*glVertex3i((zoomScopePosition.X-1)*sdl_scale, (YRES+MENUSIZE-(zoomScopePosition.Y-1))*sdl_scale, 0); - glVertex3i((zoomScopePosition.X-1)*sdl_scale, (YRES+MENUSIZE-(zoomScopePosition.Y+zoomScopeSize))*sdl_scale, 0); - glVertex3i((zoomScopePosition.X+zoomScopeSize)*sdl_scale, (YRES+MENUSIZE-(zoomScopePosition.Y+zoomScopeSize))*sdl_scale, 0); - glVertex3i((zoomScopePosition.X+zoomScopeSize)*sdl_scale, (YRES+MENUSIZE-(zoomScopePosition.Y-1))*sdl_scale, 0); - glVertex3i((zoomScopePosition.X-1)*sdl_scale, (YRES+MENUSIZE-(zoomScopePosition.Y-1))*sdl_scale, 0);*/ - glEnd(); - glDisable(GL_COLOR_LOGIC_OP); - } - glLineWidth(1); - glBlendFunc(origBlendSrc, origBlendDst); - #else - int x, y, i, j; - pixel pix; - pixel * img = vid; - drawrect(zoomWindowPosition.X-2, zoomWindowPosition.Y-2, zoomScopeSize*ZFACTOR+2, zoomScopeSize*ZFACTOR+2, 192, 192, 192, 255); - drawrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR, zoomScopeSize*ZFACTOR, 0, 0, 0, 255); - clearrect(zoomWindowPosition.X, zoomWindowPosition.Y, zoomScopeSize*ZFACTOR, zoomScopeSize*ZFACTOR); - for (j=0; jbmap; - unsigned char (*emap)[XRES/CELL] = sim->emap; - wall_type *wtypes = sim->wtypes; - for (y=0; y=UI_WALLCOUNT) - continue; - pc = wtypes[wt].colour; - gc = wtypes[wt].eglow; - - // standard wall patterns - if (wtypes[wt].drawstyle==1) - { - for (j=0; j>1)&1; i 255) cr = 255; - fire_r[y][x] = cr; - cg = fire_g[y][x] + PIXG(pc); - if (cg > 255) cg = 255; - fire_g[y][x] = cg; - cb = fire_b[y][x] + PIXB(pc); - if (cb > 255) cb = 255; - fire_b[y][x] = cb; - - } - } -#endif -} - -void Renderer::DrawSigns() -{ - int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq; - std::vector signs = sim->signs; -#ifdef OGLR - GLint prevFbo; - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); - glTranslated(0, MENUSIZE, 0); -#endif - for (i=0; i < signs.size(); i++) - if (signs[i].text.length()) - { - char buff[256]; //Buffer - sim->signs[i].pos(x, y, w, h); - clearrect(x, y, w, h); - drawrect(x, y, w, h, 192, 192, 192, 255); - - //Displaying special information - if (signs[i].text == "{p}") - { - float pressure = 0.0f; - if (signs[i].x>=0 && signs[i].x=0 && signs[i].ypv[signs[i].y/CELL][signs[i].x/CELL]; - sprintf(buff, "Pressure: %3.2f", pressure); //...pressure - drawtext(x+3, y+3, buff, 255, 255, 255, 255); - } - else if (signs[i].text == "{t}") - { - if (signs[i].x>=0 && signs[i].x=0 && signs[i].ypmap[signs[i].y][signs[i].x]) - sprintf(buff, "Temp: %4.2f", sim->parts[sim->pmap[signs[i].y][signs[i].x]>>8].temp-273.15); //...temperature - else - sprintf(buff, "Temp: 0.00"); //...temperature - drawtext(x+3, y+3, buff, 255, 255, 255, 255); - } - else if (sregexp(signs[i].text.c_str(), "^{c:[0-9]*|.*}$")==0) - { - int sldr, startm; - memset(buff, 0, sizeof(buff)); - for (sldr=3; signs[i].text[sldr-1] != '|'; sldr++) - startm = sldr + 1; - sldr = startm; - while (signs[i].text[sldr] != '}') - { - buff[sldr - startm] = signs[i].text[sldr]; - sldr++; - } - drawtext(x+3, y+3, buff, 0, 191, 255, 255); - } - else - { - drawtext(x+3, y+3, signs[i].text, 255, 255, 255, 255); - } - - x = signs[i].x; - y = signs[i].y; - dx = 1 - signs[i].ju; - dy = (signs[i].y > 18) ? -1 : 1; -#ifdef OGLR - glBegin(GL_LINES); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glVertex2i(x, y); - glVertex2i(x+(dx*4), y+(dy*4)); - glEnd(); -#else - for (j=0; j<4; j++) - { - blendpixel(x, y, 192, 192, 192, 255); - x+=dx; - y+=dy; - } -#endif - /*if (MSIGN==i) - { - bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; - signs[i].x = mx; - signs[i].y = my; - }*/ - } -#ifdef OGLR - glTranslated(0, -MENUSIZE, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); -#endif -} - -void Renderer::render_gravlensing() -{ -#ifndef OGLR - int nx, ny, rx, ry, gx, gy, bx, by, co; - int r, g, b; - pixel t; - pixel *src = vid; - pixel *dst = vid; - for(nx = 0; nx < XRES; nx++) - { - for(ny = 0; ny < YRES; ny++) - { - co = (ny/CELL)*(XRES/CELL)+(nx/CELL); - rx = (int)(nx-sim->gravx[co]*0.75f+0.5f); - ry = (int)(ny-sim->gravy[co]*0.75f+0.5f); - gx = (int)(nx-sim->gravx[co]*0.875f+0.5f); - gy = (int)(ny-sim->gravy[co]*0.875f+0.5f); - bx = (int)(nx-sim->gravx[co]+0.5f); - by = (int)(ny-sim->gravy[co]+0.5f); - if(rx > 0 && rx < XRES && ry > 0 && ry < YRES && gx > 0 && gx < XRES && gy > 0 && gy < YRES && bx > 0 && bx < XRES && by > 0 && by < YRES) - { - t = dst[ny*(VIDXRES)+nx]; - r = PIXR(src[ry*(VIDXRES)+rx]) + PIXR(t); - g = PIXG(src[gy*(VIDXRES)+gx]) + PIXG(t); - b = PIXB(src[by*(VIDXRES)+bx]) + PIXB(t); - if (r>255) - r = 255; - if (g>255) - g = 255; - if (b>255) - b = 255; - dst[ny*(VIDXRES)+nx] = PIXRGB(r,g,b); - } - } - } -#endif -} - -void Renderer::render_fire() -{ -#ifndef OGLR - int i,j,x,y,r,g,b,nx,ny; - for (j=0; j=0 && j+y>=0 && i+x4 ? r-4 : 0; - fire_g[j][i] = g>4 ? g-4 : 0; - fire_b[j][i] = b>4 ? b-4 : 0; - } -#endif -} - -float temp[CELL*3][CELL*3]; -float fire_alphaf[CELL*3][CELL*3]; -float glow_alphaf[11][11]; -float blur_alphaf[7][7]; -void Renderer::prepare_alpha(int size, float intensity) -{ - //TODO: implement size - int x,y,i,j,c; - float multiplier = 255.0f*intensity; - - memset(temp, 0, sizeof(temp)); - for (x=0; x 7) - continue; - glow_alphaf[c+x][c-y] += 0.02f; - glow_alphaf[c-x][c+y] += 0.02f; - glow_alphaf[c+x][c+y] += 0.02f; - glow_alphaf[c-x][c-y] += 0.02f; - } - } - - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, glowAlpha); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 11, 11, GL_ALPHA, GL_FLOAT, glow_alphaf); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - c = 3; - - for (x=-3; x<4; x++) - { - for (y=-3; y<4; y++) - { - if (abs(x)+abs(y) <2 && !(abs(x)==2||abs(y)==2)) - blur_alphaf[c+x][c-y] = 0.11f; - if (abs(x)+abs(y) <=3 && abs(x)+abs(y)) - blur_alphaf[c+x][c-y] = 0.08f; - if (abs(x)+abs(y) == 2) - blur_alphaf[c+x][c-y] = 0.04f; - } - } - - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, blurAlpha); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 7, 7, GL_ALPHA, GL_FLOAT, blur_alphaf); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); -#endif -} - -void Renderer::render_parts() -{ - int deca, decr, decg, decb, cola, colr, colg, colb, firea, firer, fireg, fireb, pixel_mode, q, i, t, nx, ny, x, y, caddress; - int orbd[4] = {0, 0, 0, 0}, orbl[4] = {0, 0, 0, 0}; - float gradv, flicker, fnx, fny; - Particle * parts; - part_transition *ptransitions; - Element *elements; - if(!sim) - return; - parts = sim->parts; - elements = sim->elements; -#ifdef OGLR - int cfireV = 0, cfireC = 0, cfire = 0; - int csmokeV = 0, csmokeC = 0, csmoke = 0; - int cblobV = 0, cblobC = 0, cblob = 0; - int cblurV = 0, cblurC = 0, cblur = 0; - int cglowV = 0, cglowC = 0, cglow = 0; - int cflatV = 0, cflatC = 0, cflat = 0; - int caddV = 0, caddC = 0, cadd = 0; - int clineV = 0, clineC = 0, cline = 0; - GLint origBlendSrc, origBlendDst, prevFbo; - - glGetIntegerv(GL_BLEND_SRC, &origBlendSrc); - glGetIntegerv(GL_BLEND_DST, &origBlendDst); - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); - //Render to the particle FBO - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); - glTranslated(0, MENUSIZE, 0); -#else - /*if (GRID_MODE)//draws the grid - { - for (ny=0; nyparts_lastActiveIndex; i++) { - if (sim->parts[i].type) { - t = sim->parts[i].type; - - nx = (int)(sim->parts[i].x+0.5f); - ny = (int)(sim->parts[i].y+0.5f); - fnx = sim->parts[i].x; - fny = sim->parts[i].y; - - if((sim->photons[ny][nx]&0xFF) && !(sim->elements[t].Properties & TYPE_ENERGY) && t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH) - continue; - if(nx >= XRES || nx < 0 || ny >= YRES || ny < 0) - continue; - - //Defaults - pixel_mode = 0 | PMODE_FLAT; - cola = 255; - colr = PIXR(elements[t].Colour); - colg = PIXG(elements[t].Colour); - colb = PIXB(elements[t].Colour); - firea = 0; - - deca = (sim->parts[i].dcolour>>24)&0xFF; - decr = (sim->parts[i].dcolour>>16)&0xFF; - decg = (sim->parts[i].dcolour>>8)&0xFF; - decb = (sim->parts[i].dcolour)&0xFF; - - { - if (graphicscache[t].isready) - { - pixel_mode = graphicscache[t].pixel_mode; - cola = graphicscache[t].cola; - colr = graphicscache[t].colr; - colg = graphicscache[t].colg; - colb = graphicscache[t].colb; - firea = graphicscache[t].firea; - firer = graphicscache[t].firer; - fireg = graphicscache[t].fireg; - fireb = graphicscache[t].fireb; - } - else if(!(colour_mode & COLOUR_BASC)) - { - if (elements[t].Graphics) - { - if ((*(elements[t].Graphics))(this, &(sim->parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb)) //That's a lot of args, a struct might be better - { - graphicscache[t].isready = 1; - graphicscache[t].pixel_mode = pixel_mode; - graphicscache[t].cola = cola; - graphicscache[t].colr = colr; - graphicscache[t].colg = colg; - graphicscache[t].colb = colb; - graphicscache[t].firea = firea; - graphicscache[t].firer = firer; - graphicscache[t].fireg = fireg; - graphicscache[t].fireb = fireb; - } - } - else - { - graphicscache[t].isready = 1; - graphicscache[t].pixel_mode = pixel_mode; - graphicscache[t].cola = cola; - graphicscache[t].colr = colr; - graphicscache[t].colg = colg; - graphicscache[t].colb = colb; - graphicscache[t].firea = firea; - graphicscache[t].firer = firer; - graphicscache[t].fireg = fireg; - graphicscache[t].fireb = fireb; - } - } - if((elements[t].Properties & PROP_HOT_GLOW) && sim->parts[i].temp>(elements[t].HighTemperature-800.0f)) - { - gradv = 3.1415/(2*elements[t].HighTemperature-(elements[t].HighTemperature-800.0f)); - caddress = (sim->parts[i].temp>elements[t].HighTemperature)?elements[t].HighTemperature-(elements[t].HighTemperature-800.0f):sim->parts[i].temp-(elements[t].HighTemperature-800.0f); - colr += sin(gradv*caddress) * 226;; - colg += sin(gradv*caddress*4.55 +3.14) * 34; - colb += sin(gradv*caddress*2.22 +3.14) * 64; - } - - if((pixel_mode & FIRE_ADD) && !(render_mode & FIRE_ADD)) - pixel_mode |= PMODE_GLOW; - if((pixel_mode & FIRE_BLEND) && !(render_mode & FIRE_BLEND)) - pixel_mode |= PMODE_BLUR; - if((pixel_mode & PMODE_BLUR) && !(render_mode & PMODE_BLUR)) - pixel_mode |= PMODE_FLAT; - if((pixel_mode & PMODE_GLOW) && !(render_mode & PMODE_GLOW)) - pixel_mode |= PMODE_BLEND; - if (render_mode & PMODE_BLOB) - pixel_mode |= PMODE_BLOB; - - pixel_mode &= render_mode; - - //Alter colour based on display mode - if(colour_mode & COLOUR_HEAT) - { - caddress = restrict_flt((int)( restrict_flt((float)(sim->parts[i].temp+(-MIN_TEMP)), 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); - firea = 255; - firer = colr = (unsigned char)color_data[caddress]; - fireg = colg = (unsigned char)color_data[caddress+1]; - fireb = colb = (unsigned char)color_data[caddress+2]; - cola = 255; - if(pixel_mode & (FIREMODE | PMODE_GLOW)) pixel_mode = (pixel_mode & ~(FIREMODE|PMODE_GLOW)) | PMODE_BLUR; - } - else if(colour_mode & COLOUR_LIFE) - { - gradv = 0.4f; - if (!(sim->parts[i].life<5)) - q = sqrt(sim->parts[i].life); - else - q = sim->parts[i].life; - colr = colg = colb = sin(gradv*q) * 100 + 128; - cola = 255; - if(pixel_mode & (FIREMODE | PMODE_GLOW)) pixel_mode = (pixel_mode & ~(FIREMODE|PMODE_GLOW)) | PMODE_BLUR; - } - else if(colour_mode & COLOUR_BASC) - { - colr = PIXR(elements[t].Colour); - colg = PIXG(elements[t].Colour); - colb = PIXB(elements[t].Colour); - pixel_mode = PMODE_FLAT; - } - - //Apply decoration colour - if(!(colour_mode & ~COLOUR_GRAD)) - { - if(!(pixel_mode & NO_DECO) && decorations_enable) - { - colr = (deca*decr + (255-deca)*colr) >> 8; - colg = (deca*decg + (255-deca)*colg) >> 8; - colb = (deca*decb + (255-deca)*colb) >> 8; - } - - if((pixel_mode & DECO_FIRE) && decorations_enable) - { - firer = (deca*decr + (255-deca)*firer) >> 8; - fireg = (deca*decg + (255-deca)*fireg) >> 8; - fireb = (deca*decb + (255-deca)*fireb) >> 8; - } - } - - if (colour_mode & COLOUR_GRAD) - { - float frequency = 0.05; - int q = sim->parts[i].temp-40; - colr = sin(frequency*q) * 16 + colr; - colg = sin(frequency*q) * 16 + colg; - colb = sin(frequency*q) * 16 + colb; - if(pixel_mode & (FIREMODE | PMODE_GLOW)) pixel_mode = (pixel_mode & ~(FIREMODE|PMODE_GLOW)) | PMODE_BLUR; - } - - #ifndef OGLR - //All colours are now set, check ranges - if(colr>255) colr = 255; - else if(colr<0) colr = 0; - if(colg>255) colg = 255; - else if(colg<0) colg = 0; - if(colb>255) colb = 255; - else if(colb<0) colb = 0; - if(cola>255) cola = 255; - else if(cola<0) cola = 0; - - if(firer>255) firer = 255; - else if(firer<0) firer = 0; - if(fireg>255) fireg = 255; - else if(fireg<0) fireg = 0; - if(fireb>255) fireb = 255; - else if(fireb<0) fireb = 0; - if(firea>255) firea = 255; - else if(firea<0) firea = 0; - #endif - - //Pixel rendering - if(pixel_mode & PSPEC_STICKMAN) - { - char buff[20]; //Buffer for HP - int s; - int legr, legg, legb; - playerst *cplayer; - if(t==PT_STKM) - cplayer = &sim->player; - else if(t==PT_STKM2) - cplayer = &sim->player2; - else if(t==PT_FIGH) - cplayer = &sim->fighters[(unsigned char)sim->parts[i].tmp]; - else - continue; - -/* if (mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head - { - sprintf(buff, "%3d", sim->parts[i].life); //Show HP - drawtext(mousex-8-2*(sim->parts[i].life<100)-2*(sim->parts[i].life<10), mousey-12, buff, 255, 255, 255, 255); - }*/ - - if (colour_mode!=COLOUR_HEAT) - { - if (cplayer->elemelem].Colour); - colg = PIXG(elements[cplayer->elem].Colour); - colb = PIXB(elements[cplayer->elem].Colour); - } - else - { - colr = 0x80; - colg = 0x80; - colb = 0xFF; - } - } -#ifdef OGLR - glColor4f(((float)colr)/255.0f, ((float)colg)/255.0f, ((float)colb)/255.0f, 1.0f); - glBegin(GL_LINE_STRIP); - if(t==PT_FIGH) - { - glVertex2f(fnx, fny+2); - glVertex2f(fnx+2, fny); - glVertex2f(fnx, fny-2); - glVertex2f(fnx-2, fny); - glVertex2f(fnx, fny+2); - } - else - { - glVertex2f(fnx-2, fny-2); - glVertex2f(fnx+2, fny-2); - glVertex2f(fnx+2, fny+2); - glVertex2f(fnx-2, fny+2); - glVertex2f(fnx-2, fny-2); - } - glEnd(); - glBegin(GL_LINES); - - if (colour_mode!=COLOUR_HEAT) - { - if (t==PT_STKM2) - glColor4f(100.0f/255.0f, 100.0f/255.0f, 1.0f, 1.0f); - else - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - } - - glVertex2f(nx, ny+3); - glVertex2f(cplayer->legs[0], cplayer->legs[1]); - - glVertex2f(cplayer->legs[0], cplayer->legs[1]); - glVertex2f(cplayer->legs[4], cplayer->legs[5]); - - glVertex2f(nx, ny+3); - glVertex2f(cplayer->legs[8], cplayer->legs[9]); - - glVertex2f(cplayer->legs[8], cplayer->legs[9]); - glVertex2f(cplayer->legs[12], cplayer->legs[13]); - glEnd(); -#else - s = VIDXRES; - - if (t==PT_STKM2) - { - legr = 100; - legg = 100; - legb = 255; - } - else - { - legr = 255; - legg = 255; - legb = 255; - } - - if (colour_mode==COLOUR_HEAT) - { - legr = colr; - legg = colg; - legb = colb; - } - - //head - if(t==PT_FIGH) - { - draw_line(nx, ny+2, nx+2, ny, colr, colg, colb, s); - draw_line(nx+2, ny, nx, ny-2, colr, colg, colb, s); - draw_line(nx, ny-2, nx-2, ny, colr, colg, colb, s); - draw_line(nx-2, ny, nx, ny+2, colr, colg, colb, s); - } - else - { - draw_line(nx-2, ny+2, nx+2, ny+2, colr, colg, colb, s); - draw_line(nx-2, ny-2, nx+2, ny-2, colr, colg, colb, s); - draw_line(nx-2, ny-2, nx-2, ny+2, colr, colg, colb, s); - draw_line(nx+2, ny-2, nx+2, ny+2, colr, colg, colb, s); - } - //legs - draw_line(nx, ny+3, cplayer->legs[0], cplayer->legs[1], legr, legg, legb, s); - draw_line(cplayer->legs[0], cplayer->legs[1], cplayer->legs[4], cplayer->legs[5], legr, legg, legb, s); - draw_line(nx, ny+3, cplayer->legs[8], cplayer->legs[9], legr, legg, legb, s); - draw_line(cplayer->legs[8], cplayer->legs[9], cplayer->legs[12], cplayer->legs[13], legr, legg, legb, s); -#endif - } - if(pixel_mode & PMODE_FLAT) - { -#ifdef OGLR - flatV[cflatV++] = nx; - flatV[cflatV++] = ny; - flatC[cflatC++] = ((float)colr)/255.0f; - flatC[cflatC++] = ((float)colg)/255.0f; - flatC[cflatC++] = ((float)colb)/255.0f; - flatC[cflatC++] = 1.0f; - cflat++; -#else - vid[ny*(VIDXRES)+nx] = PIXRGB(colr,colg,colb); -#endif - } - if(pixel_mode & PMODE_BLEND) - { -#ifdef OGLR - flatV[cflatV++] = nx; - flatV[cflatV++] = ny; - flatC[cflatC++] = ((float)colr)/255.0f; - flatC[cflatC++] = ((float)colg)/255.0f; - flatC[cflatC++] = ((float)colb)/255.0f; - flatC[cflatC++] = ((float)cola)/255.0f; - cflat++; -#else - blendpixel(nx, ny, colr, colg, colb, cola); -#endif - } - if(pixel_mode & PMODE_ADD) - { -#ifdef OGLR - addV[caddV++] = nx; - addV[caddV++] = ny; - addC[caddC++] = ((float)colr)/255.0f; - addC[caddC++] = ((float)colg)/255.0f; - addC[caddC++] = ((float)colb)/255.0f; - addC[caddC++] = ((float)cola)/255.0f; - cadd++; -#else - addpixel(nx, ny, colr, colg, colb, cola); -#endif - } - if(pixel_mode & PMODE_BLOB) - { -#ifdef OGLR - blobV[cblobV++] = nx; - blobV[cblobV++] = ny; - blobC[cblobC++] = ((float)colr)/255.0f; - blobC[cblobC++] = ((float)colg)/255.0f; - blobC[cblobC++] = ((float)colb)/255.0f; - blobC[cblobC++] = 1.0f; - cblob++; -#else - vid[ny*(VIDXRES)+nx] = PIXRGB(colr,colg,colb); - - blendpixel(nx+1, ny, colr, colg, colb, 223); - blendpixel(nx-1, ny, colr, colg, colb, 223); - blendpixel(nx, ny+1, colr, colg, colb, 223); - blendpixel(nx, ny-1, colr, colg, colb, 223); - - blendpixel(nx+1, ny-1, colr, colg, colb, 112); - blendpixel(nx-1, ny-1, colr, colg, colb, 112); - blendpixel(nx+1, ny+1, colr, colg, colb, 112); - blendpixel(nx-1, ny+1, colr, colg, colb, 112); -#endif - } - if(pixel_mode & PMODE_GLOW) - { - int cola1 = (5*cola)/255; -#ifdef OGLR - glowV[cglowV++] = nx; - glowV[cglowV++] = ny; - glowC[cglowC++] = ((float)colr)/255.0f; - glowC[cglowC++] = ((float)colg)/255.0f; - glowC[cglowC++] = ((float)colb)/255.0f; - glowC[cglowC++] = 1.0f; - cglow++; -#else - addpixel(nx, ny, colr, colg, colb, (192*cola)/255); - addpixel(nx+1, ny, colr, colg, colb, (96*cola)/255); - addpixel(nx-1, ny, colr, colg, colb, (96*cola)/255); - addpixel(nx, ny+1, colr, colg, colb, (96*cola)/255); - addpixel(nx, ny-1, colr, colg, colb, (96*cola)/255); - - for (x = 1; x < 6; x++) { - addpixel(nx, ny-x, colr, colg, colb, cola1); - addpixel(nx, ny+x, colr, colg, colb, cola1); - addpixel(nx-x, ny, colr, colg, colb, cola1); - addpixel(nx+x, ny, colr, colg, colb, cola1); - for (y = 1; y < 6; y++) { - if(x + y > 7) - continue; - addpixel(nx+x, ny-y, colr, colg, colb, cola1); - addpixel(nx-x, ny+y, colr, colg, colb, cola1); - addpixel(nx+x, ny+y, colr, colg, colb, cola1); - addpixel(nx-x, ny-y, colr, colg, colb, cola1); - } - } -#endif - } - if(pixel_mode & PMODE_BLUR) - { -#ifdef OGLR - blurV[cblurV++] = nx; - blurV[cblurV++] = ny; - blurC[cblurC++] = ((float)colr)/255.0f; - blurC[cblurC++] = ((float)colg)/255.0f; - blurC[cblurC++] = ((float)colb)/255.0f; - blurC[cblurC++] = 1.0f; - cblur++; -#else - for (x=-3; x<4; x++) - { - for (y=-3; y<4; y++) - { - if (abs(x)+abs(y) <2 && !(abs(x)==2||abs(y)==2)) - blendpixel(x+nx, y+ny, colr, colg, colb, 30); - if (abs(x)+abs(y) <=3 && abs(x)+abs(y)) - blendpixel(x+nx, y+ny, colr, colg, colb, 20); - if (abs(x)+abs(y) == 2) - blendpixel(x+nx, y+ny, colr, colg, colb, 10); - } - } -#endif - } - if(pixel_mode & PMODE_SPARK) - { - flicker = rand()%20; -#ifdef OGLR - //Oh god, this is awful - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx-5; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 1.0f - ((float)flicker)/30; - lineV[clineV++] = fnx; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx+5; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx; - lineV[clineV++] = fny-5; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 1.0f - ((float)flicker)/30; - lineV[clineV++] = fnx; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx; - lineV[clineV++] = fny+5; - cline++; -#else - gradv = 4*sim->parts[i].life + flicker; - for (x = 0; gradv>0.5; x++) { - addpixel(nx+x, ny, colr, colg, colb, gradv); - addpixel(nx-x, ny, colr, colg, colb, gradv); - - addpixel(nx, ny+x, colr, colg, colb, gradv); - addpixel(nx, ny-x, colr, colg, colb, gradv); - gradv = gradv/1.5f; - } -#endif - } - if(pixel_mode & PMODE_FLARE) - { - flicker = rand()%20; -#ifdef OGLR - //Oh god, this is awful - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx-10; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 1.0f - ((float)flicker)/40; - lineV[clineV++] = fnx; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx+10; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx; - lineV[clineV++] = fny-10; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 1.0f - ((float)flicker)/30; - lineV[clineV++] = fnx; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx; - lineV[clineV++] = fny+10; - cline++; -#else - gradv = flicker + fabs(parts[i].vx)*17 + fabs(sim->parts[i].vy)*17; - blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); - blendpixel(nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - if (gradv>255) gradv=255; - blendpixel(nx+1, ny-1, colr, colg, colb, gradv); - blendpixel(nx-1, ny-1, colr, colg, colb, gradv); - blendpixel(nx+1, ny+1, colr, colg, colb, gradv); - blendpixel(nx-1, ny+1, colr, colg, colb, gradv); - for (x = 1; gradv>0.5; x++) { - addpixel(nx+x, ny, colr, colg, colb, gradv); - addpixel(nx-x, ny, colr, colg, colb, gradv); - addpixel(nx, ny+x, colr, colg, colb, gradv); - addpixel(nx, ny-x, colr, colg, colb, gradv); - gradv = gradv/1.2f; - } -#endif - } - if(pixel_mode & PMODE_LFLARE) - { - flicker = rand()%20; -#ifdef OGLR - //Oh god, this is awful - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx-70; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 1.0f - ((float)flicker)/30; - lineV[clineV++] = fnx; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx+70; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx; - lineV[clineV++] = fny-70; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 1.0f - ((float)flicker)/50; - lineV[clineV++] = fnx; - lineV[clineV++] = fny; - cline++; - - lineC[clineC++] = ((float)colr)/255.0f; - lineC[clineC++] = ((float)colg)/255.0f; - lineC[clineC++] = ((float)colb)/255.0f; - lineC[clineC++] = 0.0f; - lineV[clineV++] = fnx; - lineV[clineV++] = fny+70; - cline++; -#else - gradv = flicker + fabs(parts[i].vx)*17 + fabs(parts[i].vy)*17; - blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); - blendpixel(nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - if (gradv>255) gradv=255; - blendpixel(nx+1, ny-1, colr, colg, colb, gradv); - blendpixel(nx-1, ny-1, colr, colg, colb, gradv); - blendpixel(nx+1, ny+1, colr, colg, colb, gradv); - blendpixel(nx-1, ny+1, colr, colg, colb, gradv); - for (x = 1; gradv>0.5; x++) { - addpixel(nx+x, ny, colr, colg, colb, gradv); - addpixel(nx-x, ny, colr, colg, colb, gradv); - addpixel(nx, ny+x, colr, colg, colb, gradv); - addpixel(nx, ny-x, colr, colg, colb, gradv); - gradv = gradv/1.01f; - } -#endif - } - if (pixel_mode & EFFECT_GRAVIN) - { - int nxo = 0; - int nyo = 0; - int r; - int fire_rv = 0; - float drad = 0.0f; - float ddist = 0.0f; - sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); - for (r = 0; r < 4; r++) { - ddist = ((float)orbd[r])/16.0f; - drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; - nxo = ddist*cos(drad); - nyo = ddist*sin(drad); - if (ny+nyo>0 && ny+nyo0 && nx+nxoorbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); - for (r = 0; r < 4; r++) { - ddist = ((float)orbd[r])/16.0f; - drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; - nxo = ddist*cos(drad); - nyo = ddist*sin(drad); - if (ny+nyo>0 && ny+nyo0 && nx+nxo> 8; - fire_g[ny/CELL][nx/CELL] = (firea*fireg + (255-firea)*fire_g[ny/CELL][nx/CELL]) >> 8; - fire_b[ny/CELL][nx/CELL] = (firea*fireb + (255-firea)*fire_b[ny/CELL][nx/CELL]) >> 8; -#endif - } - if(firea && (pixel_mode & FIRE_ADD)) - { -#ifdef OGLR - fireV[cfireV++] = nx; - fireV[cfireV++] = ny; - fireC[cfireC++] = ((float)firer)/255.0f; - fireC[cfireC++] = ((float)fireg)/255.0f; - fireC[cfireC++] = ((float)fireb)/255.0f; - fireC[cfireC++] = ((float)firea)/255.0f; - cfire++; -#else - firea /= 8; - firer = ((firea*firer) >> 8) + fire_r[ny/CELL][nx/CELL]; - fireg = ((firea*fireg) >> 8) + fire_g[ny/CELL][nx/CELL]; - fireb = ((firea*fireb) >> 8) + fire_b[ny/CELL][nx/CELL]; - - if(firer>255) - firer = 255; - if(fireg>255) - fireg = 255; - if(fireb>255) - fireb = 255; - - fire_r[ny/CELL][nx/CELL] = firer; - fire_g[ny/CELL][nx/CELL] = fireg; - fire_b[ny/CELL][nx/CELL] = fireb; -#endif - } - } - } - } -#ifdef OGLR - - //Go into array mode - glEnableClientState(GL_COLOR_ARRAY); - glEnableClientState(GL_VERTEX_ARRAY); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - if(cflat) - { - // -- BEGIN FLAT -- // - //Set point size (size of fire texture) - glPointSize(1.0f); - - glColorPointer(4, GL_FLOAT, 0, &flatC[0]); - glVertexPointer(2, GL_INT, 0, &flatV[0]); - - glDrawArrays(GL_POINTS, 0, cflat); - - //Clear some stuff we set - // -- END FLAT -- // - } - - if(cblob) - { - // -- BEGIN BLOB -- // - glEnable( GL_POINT_SMOOTH ); //Blobs! - glPointSize(2.5f); - - glColorPointer(4, GL_FLOAT, 0, &blobC[0]); - glVertexPointer(2, GL_INT, 0, &blobV[0]); - - glDrawArrays(GL_POINTS, 0, cblob); - - //Clear some stuff we set - glDisable( GL_POINT_SMOOTH ); - // -- END BLOB -- // - } - - if(cglow || cblur) - { - // -- BEGIN GLOW -- // - //Start and prepare fire program - glEnable(GL_TEXTURE_2D); - glUseProgram(fireProg); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, glowAlpha); - glUniform1i(glGetUniformLocation(fireProg, "fireAlpha"), 0); - - glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); - - //Make sure we can use texture coords on points - glEnable(GL_POINT_SPRITE); - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); - glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); - - //Set point size (size of fire texture) - glPointSize(11.0f); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - - if(cglow) - { - glColorPointer(4, GL_FLOAT, 0, &glowC[0]); - glVertexPointer(2, GL_INT, 0, &glowV[0]); - - glDrawArrays(GL_POINTS, 0, cglow); - } - - glPointSize(7.0f); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - if(cblur) - { - glBindTexture(GL_TEXTURE_2D, blurAlpha); - - glColorPointer(4, GL_FLOAT, 0, &blurC[0]); - glVertexPointer(2, GL_INT, 0, &blurV[0]); - - glDrawArrays(GL_POINTS, 0, cblur); - } - - //Clear some stuff we set - glDisable(GL_POINT_SPRITE); - glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); - glUseProgram(0); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - // -- END GLOW -- // - } - - if(cadd) - { - // -- BEGIN ADD -- // - //Set point size (size of fire texture) - glPointSize(1.0f); - - glColorPointer(4, GL_FLOAT, 0, &addC[0]); - glVertexPointer(2, GL_INT, 0, &addV[0]); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - glDrawArrays(GL_POINTS, 0, cadd); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - //Clear some stuff we set - // -- END ADD -- // - } - - if(cline) - { - // -- BEGIN LINES -- // - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - glEnable( GL_LINE_SMOOTH ); - glColorPointer(4, GL_FLOAT, 0, &lineC[0]); - glVertexPointer(2, GL_FLOAT, 0, &lineV[0]); - - glDrawArrays(GL_LINE_STRIP, 0, cline); - - //Clear some stuff we set - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable(GL_LINE_SMOOTH); - // -- END LINES -- // - } - - if(cfire || csmoke) - { - // -- BEGIN FIRE -- // - //Start and prepare fire program - glEnable(GL_TEXTURE_2D); - glUseProgram(fireProg); - //glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, fireAlpha); - glUniform1i(glGetUniformLocation(fireProg, "fireAlpha"), 0); - - //Make sure we can use texture coords on points - glEnable(GL_POINT_SPRITE); - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); - glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); - - //Set point size (size of fire texture) - glPointSize(CELL*3); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - - if(cfire) - { - glColorPointer(4, GL_FLOAT, 0, &fireC[0]); - glVertexPointer(2, GL_INT, 0, &fireV[0]); - - glDrawArrays(GL_POINTS, 0, cfire); - } - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - if(csmoke) - { - glColorPointer(4, GL_FLOAT, 0, &smokeC[0]); - glVertexPointer(2, GL_INT, 0, &smokeV[0]); - - glDrawArrays(GL_POINTS, 0, csmoke); - } - - //Clear some stuff we set - glDisable(GL_POINT_SPRITE); - glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); - glUseProgram(0); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - // -- END FIRE -- // - } - - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - - //Reset FBO - glTranslated(0, -MENUSIZE, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); - - glBlendFunc(origBlendSrc, origBlendDst); -#endif -} - -void Renderer::draw_other() // EMP effect -{ - int i, j; - //if (emp_decor>0 && !sys_pause) emp_decor-=emp_decor/25+2; TODO: Render should render only, do not change simulation state - if (emp_decor>40) emp_decor=40; - if (emp_decor<0) emp_decor = 0; - if (!(display_mode & DISPLAY_EFFE)) // no in nothing mode - return; - if (emp_decor>0) - { -#ifdef OGLR - GLint prevFbo; - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); - glTranslated(0, MENUSIZE, 0); - float femp_decor = ((float)emp_decor)/255.0f; - /*int r=emp_decor*2.5, g=100+emp_decor*1.5, b=255; - int a=(1.0*emp_decor/110)*255; - if (r>255) r=255; - if (g>255) g=255; - if (b>255) g=255; - if (a>255) a=255;*/ - glBegin(GL_QUADS); - glColor4f(femp_decor*2.5f, 0.4f+femp_decor*1.5f, 1.0f+femp_decor*1.5f, femp_decor/0.44f); - glVertex2f(0, MENUSIZE); - glVertex2f(XRES, MENUSIZE); - glVertex2f(XRES, YRES+MENUSIZE); - glVertex2f(0, YRES+MENUSIZE); - glEnd(); - glTranslated(0, -MENUSIZE, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); -#else - int r=emp_decor*2.5, g=100+emp_decor*1.5, b=255; - int a=(1.0*emp_decor/110)*255; - if (r>255) r=255; - if (g>255) g=255; - if (b>255) g=255; - if (a>255) a=255; - for (j=0; jgravx[ca]) <= 0.001f && fabsf(sim->gravy[ca]) <= 0.001f) - continue; - nx = x*CELL; - ny = y*CELL; - dist = fabsf(sim->gravy[ca])+fabsf(sim->gravx[ca]); - for(i = 0; i < 4; i++) - { - nx -= sim->gravx[ca]*0.5f; - ny -= sim->gravy[ca]*0.5f; - addpixel((int)(nx+0.5f), (int)(ny+0.5f), 255, 255, 255, (int)(dist*20.0f)); - } - } - } -} - -void Renderer::draw_air() -{ -#ifndef OGLR - if(!(display_mode & DISPLAY_AIR)) - return; - int x, y, i, j; - float (*pv)[XRES/CELL] = sim->air->pv; - float (*hv)[XRES/CELL] = sim->air->hv; - float (*vx)[XRES/CELL] = sim->air->vx; - float (*vy)[XRES/CELL] = sim->air->vy; - pixel c; - for (y=0; y 0.0f) - c = PIXRGB(clamp_flt(pv[y][x], 0.0f, 8.0f), 0, 0);//positive pressure is red! - else - c = PIXRGB(0, 0, clamp_flt(-pv[y][x], 0.0f, 8.0f));//negative pressure is blue! - } - else if (display_mode & DISPLAY_AIRV) - { - c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red - clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green - clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue - } - else if (display_mode & DISPLAY_AIRH) - { - float ttemp = hv[y][x]+(-MIN_TEMP); - int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); - c = PIXRGB((int)((unsigned char)color_data[caddress]*0.7f), (int)((unsigned char)color_data[caddress+1]*0.7f), (int)((unsigned char)color_data[caddress+2]*0.7f)); - //c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red - // clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green - // clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue - } - else if (display_mode & DISPLAY_AIRC) - { - int r; - int g; - int b; - // velocity adds grey - r = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); - g = clamp_flt(fabsf(vx[y][x]), 0.0f, 20.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 24.0f); - b = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); - if (pv[y][x] > 0.0f) - { - r += clamp_flt(pv[y][x], 0.0f, 16.0f);//pressure adds red! - if (r>255) - r=255; - if (g>255) - g=255; - if (b>255) - b=255; - c = PIXRGB(r, g, b); - } - else - { - b += clamp_flt(-pv[y][x], 0.0f, 16.0f);//pressure adds blue! - if (r>255) - r=255; - if (g>255) - g=255; - if (b>255) - b=255; - c = PIXRGB(r, g, b); - } - } - for (j=0; jair->vx); - glUniform1i(glGetUniformLocation(airProg, "airX"), 0); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, airVY); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_GREEN, GL_FLOAT, sim->air->vy); - glUniform1i(glGetUniformLocation(airProg, "airY"), 1); - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, airPV); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_BLUE, GL_FLOAT, sim->air->pv); - glUniform1i(glGetUniformLocation(airProg, "airP"), 2); - glActiveTexture(GL_TEXTURE0); - - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glBegin(GL_QUADS); - glTexCoord2d(1, 1); - glVertex3f(XRES*sdl_scale, YRES*sdl_scale, 1.0); - glTexCoord2d(0, 1); - glVertex3f(0, YRES*sdl_scale, 1.0); - glTexCoord2d(0, 0); - glVertex3f(0, 0, 1.0); - glTexCoord2d(1, 0); - glVertex3f(XRES*sdl_scale, 0, 1.0); - glEnd(); - - glUseProgram(0); - glBindTexture(GL_TEXTURE_2D, 0); - glTranslated(0, -MENUSIZE, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); - glDisable( GL_TEXTURE_2D ); -#endif -} - -void Renderer::draw_grav_zones() -{ - int x, y, i, j; - for (y=0; ygravmask[y*(XRES/CELL)+x]) - { - for (j=0; jg = g; - this->sim = sim; -#if !defined(OGLR) -#if defined(OGLI) - vid = new pixel[VIDXRES*VIDYRES]; -#else - vid = g->vid; -#endif -#endif - - memset(fire_r, 0, sizeof(fire_r)); - memset(fire_g, 0, sizeof(fire_g)); - memset(fire_b, 0, sizeof(fire_b)); - - //Set defauly display modes - SetColourMode(COLOUR_DEFAULT); - AddRenderMode(RENDER_BASC); - AddRenderMode(RENDER_FIRE); - - //Prepare the graphics cache - graphicscache = (gcache_item *)malloc(sizeof(gcache_item)*PT_NUM); - memset(graphicscache, 0, sizeof(gcache_item)*PT_NUM); - - int fireColoursCount = 4; - pixel fireColours[] = {PIXPACK(0xAF9F0F), PIXPACK(0xDFBF6F), PIXPACK(0x60300F), PIXPACK(0x000000)}; - float fireColoursPoints[] = {1.0f, 0.9f, 0.5f, 0.0f}; - - int plasmaColoursCount = 5; - pixel plasmaColours[] = {PIXPACK(0xAFFFFF), PIXPACK(0xAFFFFF), PIXPACK(0x301060), PIXPACK(0x301040), PIXPACK(0x000000)}; - float plasmaColoursPoints[] = {1.0f, 0.9f, 0.5f, 0.25, 0.0f}; - - flm_data = Graphics::GenerateGradient(fireColours, fireColoursPoints, fireColoursCount, 200); - plasma_data = Graphics::GenerateGradient(plasmaColours, plasmaColoursPoints, plasmaColoursCount, 200); - -#ifdef OGLR - //FBO Texture - glEnable(GL_TEXTURE_2D); - glGenTextures(1, &partsFboTex); - glBindTexture(GL_TEXTURE_2D, partsFboTex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, XRES, YRES, 0, GL_RGBA, GL_FLOAT, NULL); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - - //FBO - glGenFramebuffers(1, &partsFbo); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); - glEnable(GL_BLEND); - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, partsFboTex, 0); - glBindTexture(GL_TEXTURE_2D, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // Reset framebuffer binding - glDisable(GL_TEXTURE_2D); - - //Texture for air to be drawn - glEnable(GL_TEXTURE_2D); - glGenTextures(1, &airBuf); - glBindTexture(GL_TEXTURE_2D, airBuf); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - //Zoom texture - glEnable(GL_TEXTURE_2D); - glGenTextures(1, &zoomTex); - glBindTexture(GL_TEXTURE_2D, zoomTex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - //Texture for velocity maps for gravity - glEnable(GL_TEXTURE_2D); - glGenTextures(1, &partsTFX); - glBindTexture(GL_TEXTURE_2D, partsTFX); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - - glBindTexture(GL_TEXTURE_2D, 0); - glGenTextures(1, &partsTFY); - glBindTexture(GL_TEXTURE_2D, partsTFY); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - //Texture for velocity maps for air - //TODO: Combine all air maps into 3D array or structs - glEnable(GL_TEXTURE_2D); - glGenTextures(1, &airVX); - glBindTexture(GL_TEXTURE_2D, airVX); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - - glBindTexture(GL_TEXTURE_2D, 0); - glGenTextures(1, &airVY); - glBindTexture(GL_TEXTURE_2D, airVY); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - - glBindTexture(GL_TEXTURE_2D, 0); - glGenTextures(1, &airPV); - glBindTexture(GL_TEXTURE_2D, airPV); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - //Fire alpha texture - glEnable(GL_TEXTURE_2D); - glGenTextures(1, &fireAlpha); - glBindTexture(GL_TEXTURE_2D, fireAlpha); - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, CELL*3, CELL*3, 0, GL_ALPHA, GL_FLOAT, NULL); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - //Glow alpha texture - glEnable(GL_TEXTURE_2D); - glGenTextures(1, &glowAlpha); - glBindTexture(GL_TEXTURE_2D, glowAlpha); - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 11, 11, 0, GL_ALPHA, GL_FLOAT, NULL); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - - //Blur Alpha texture - glEnable(GL_TEXTURE_2D); - glGenTextures(1, &blurAlpha); - glBindTexture(GL_TEXTURE_2D, blurAlpha); - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 7, 7, 0, GL_ALPHA, GL_FLOAT, NULL); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - loadShaders(); -#endif - prepare_alpha(CELL, 1.0f); -} - -void Renderer::CompileRenderMode() -{ - render_mode = 0; - for(int i = 0; i < render_modes.size(); i++) - render_mode |= render_modes[i]; -} - -void Renderer::AddRenderMode(unsigned int mode) -{ - for(int i = 0; i < render_modes.size(); i++) - { - if(render_modes[i] == mode) - { - return; - } - } - render_modes.push_back(mode); - CompileRenderMode(); -} - -void Renderer::RemoveRenderMode(unsigned int mode) -{ - for(int i = 0; i < render_modes.size(); i++) - { - if(render_modes[i] == mode) - { - render_modes.erase(render_modes.begin() + i); - i = 0; - } - } - CompileRenderMode(); -} - -void Renderer::SetRenderMode(std::vector render) -{ - render_modes = render; - CompileRenderMode(); -} - -std::vector Renderer::GetRenderMode() -{ - return render_modes; -} - -void Renderer::CompileDisplayMode() -{ - display_mode = 0; - for(int i = 0; i < display_modes.size(); i++) - display_mode |= display_modes[i]; -} - -void Renderer::AddDisplayMode(unsigned int mode) -{ - for(int i = 0; i < display_modes.size(); i++) - { - if(display_modes[i] == mode) - { - return; - } - } - display_modes.push_back(mode); - CompileDisplayMode(); -} - -void Renderer::RemoveDisplayMode(unsigned int mode) -{ - for(int i = 0; i < display_modes.size(); i++) - { - if(display_modes[i] == mode) - { - display_modes.erase(display_modes.begin() + i); - i = 0; - } - } - CompileDisplayMode(); -} - -void Renderer::SetDisplayMode(std::vector display) -{ - display_modes = display; - CompileDisplayMode(); -} - -std::vector Renderer::GetDisplayMode() -{ - return display_modes; -} - -void Renderer::SetColourMode(unsigned int mode) -{ - colour_mode = mode; -} - -unsigned int Renderer::GetColourMode() -{ - return colour_mode; -} - -Renderer::~Renderer() -{ - free(graphicscache); - free(flm_data); - free(plasma_data); -} - -#define PIXELMETHODS_CLASS Renderer -#include "PixelMethods.inc" -#undef PIXELMETHODS_CLASS - diff --git a/src/Renderer.h b/src/Renderer.h deleted file mode 100644 index b414fe4..0000000 --- a/src/Renderer.h +++ /dev/null @@ -1,146 +0,0 @@ -#ifndef RENDERER_H -#define RENDERER_H - -#include -#ifdef OGLR -#include "OpenGLHeaders.h" -#endif - -#include "Config.h" -#include "client/Client.h" -#include "simulation/Simulation.h" -#include "Graphics.h" -#include "interface/Point.h" - -class Simulation; - -class Graphics; - -struct gcache_item -{ - int isready; - int pixel_mode; - int cola, colr, colg, colb; - int firea, firer, fireg, fireb; -}; -typedef struct gcache_item gcache_item; - -class Renderer -{ -public: - std::vector render_modes; - unsigned int render_mode; - unsigned int colour_mode; - std::vector display_modes; - unsigned int display_mode; - // - unsigned char fire_r[YRES/CELL][XRES/CELL]; - unsigned char fire_g[YRES/CELL][XRES/CELL]; - unsigned char fire_b[YRES/CELL][XRES/CELL]; - unsigned int fire_alpha[CELL*3][CELL*3]; - char * flm_data; - char * plasma_data; - int emp_decor; - // - int decorations_enable; - Simulation * sim; - Graphics * g; - gcache_item *graphicscache; - - //Zoom window - ui::Point zoomWindowPosition; - ui::Point zoomScopePosition; - int zoomScopeSize; - bool zoomEnabled; - int ZFACTOR; - - //Renderers - void RenderZoom(); - void DrawWalls(); - void DrawSigns(); - void render_gravlensing(); - void render_fire(); - void prepare_alpha(int size, float intensity); - void render_parts(); - void draw_grav_zones(); - void draw_air(); - void draw_grav(); - void draw_other(); - void FinaliseParts(); - void clearScreen(float alpha); - - //class SolidsRenderer; - -#ifdef OGLR - void checkShader(GLuint shader, char * shname); - void checkProgram(GLuint program, char * progname); - void loadShaders(); -#else - pixel * vid; - void blendpixel(int x, int y, int r, int g, int b, int a); - void addpixel(int x, int y, int r, int g, int b, int a); - - void draw_icon(int x, int y, Icon icon); - - int drawtext(int x, int y, const char *s, int r, int g, int b, int a); - int drawtext(int x, int y, std::string s, int r, int g, int b, int a); - int drawchar(int x, int y, int c, int r, int g, int b, int a); - int addchar(int x, int y, int c, int r, int g, int b, int a); - - void xor_pixel(int x, int y); - void xor_line(int x, int y, int x2, int y2); - void xor_rect(int x, int y, int width, int height); - void xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h); - - void draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a); - void drawrect(int x, int y, int width, int height, int r, int g, int b, int a); - void fillrect(int x, int y, int width, int height, int r, int g, int b, int a); - void clearrect(int x, int y, int width, int height); - void gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2); - - void draw_image(pixel *img, int x, int y, int w, int h, int a); -#endif - - void drawblob(int x, int y, unsigned char cr, unsigned char cg, unsigned char cb); - //... - //Display mode modifiers - void CompileDisplayMode(); - void CompileRenderMode(); - void AddRenderMode(unsigned int mode); - void SetRenderMode(std::vector render); - std::vector GetRenderMode(); - void RemoveRenderMode(unsigned int mode); - void AddDisplayMode(unsigned int mode); - void RemoveDisplayMode(unsigned int mode); - void SetDisplayMode(std::vector display); - std::vector GetDisplayMode(); - void SetColourMode(unsigned int mode); - unsigned int GetColourMode(); - - Renderer(Graphics * g, Simulation * sim); - ~Renderer(); - -private: -#ifdef OGLR - GLuint zoomTex, airBuf, fireAlpha, glowAlpha, blurAlpha, partsFboTex, partsFbo, partsTFX, partsTFY, airPV, airVY, airVX; - GLuint fireProg, airProg_Pressure, airProg_Velocity, airProg_Cracker, lensProg; - GLuint fireV[(YRES*XRES)*2]; - GLfloat fireC[(YRES*XRES)*4]; - GLuint smokeV[(YRES*XRES)*2]; - GLfloat smokeC[(YRES*XRES)*4]; - GLuint blobV[(YRES*XRES)*2]; - GLfloat blobC[(YRES*XRES)*4]; - GLuint blurV[(YRES*XRES)*2]; - GLfloat blurC[(YRES*XRES)*4]; - GLuint glowV[(YRES*XRES)*2]; - GLfloat glowC[(YRES*XRES)*4]; - GLuint flatV[(YRES*XRES)*2]; - GLfloat flatC[(YRES*XRES)*4]; - GLuint addV[(YRES*XRES)*2]; - GLfloat addC[(YRES*XRES)*4]; - GLfloat lineV[(((YRES*XRES)*2)*6)]; - GLfloat lineC[(((YRES*XRES)*2)*6)]; -#endif -}; - -#endif diff --git a/src/client/Client.cpp b/src/client/Client.cpp index d0a7bee..3a46e23 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -18,7 +18,7 @@ #include "Config.h" #include "Client.h" #include "MD5.h" -#include "Graphics.h" +#include "graphics/Graphics.h" #include "Misc.h" #include "interface/Point.h" diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index eb01615..668b755 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -3,7 +3,7 @@ #include "GameView.h" #include "simulation/Simulation.h" #include "simulation/Air.h" -#include "Renderer.h" +#include "graphics/Renderer.h" #include "interface/Point.h" #include "Brush.h" #include "EllipseBrush.h" diff --git a/src/game/GameModel.h b/src/game/GameModel.h index 48364a7..5f656c1 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -6,7 +6,7 @@ #include "client/SaveInfo.h" #include "simulation/Simulation.h" #include "interface/Colour.h" -#include "Renderer.h" +#include "graphics/Renderer.h" #include "GameView.h" #include "Brush.h" #include "client/User.h" diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 085433f..dd03987 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -4,7 +4,7 @@ #include "Config.h" #include "Style.h" #include "GameView.h" -#include "Graphics.h" +#include "graphics/Graphics.h" #include "interface/Window.h" #include "interface/Button.h" #include "interface/Colour.h" diff --git a/src/graphics/DrawMethodsDef.inc b/src/graphics/DrawMethodsDef.inc new file mode 100644 index 0000000..4aee0c9 --- /dev/null +++ b/src/graphics/DrawMethodsDef.inc @@ -0,0 +1,17 @@ + int drawtext(int x, int y, const char *s, int r, int g, int b, int a); + int drawtext(int x, int y, std::string s, int r, int g, int b, int a); + int drawchar(int x, int y, int c, int r, int g, int b, int a); + int addchar(int x, int y, int c, int r, int g, int b, int a); + + void xor_pixel(int x, int y); + void xor_line(int x, int y, int x2, int y2); + void xor_rect(int x, int y, int width, int height); + void xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h); + + void draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a); + void drawrect(int x, int y, int width, int height, int r, int g, int b, int a); + void fillrect(int x, int y, int width, int height, int r, int g, int b, int a); + void clearrect(int x, int y, int width, int height); + void gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2); + + void draw_image(pixel *img, int x, int y, int w, int h, int a); \ No newline at end of file diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp new file mode 100644 index 0000000..5f84088 --- /dev/null +++ b/src/graphics/Graphics.cpp @@ -0,0 +1,789 @@ +#include +#include +#include +#include "Config.h" +#include "Misc.h" +#include "Graphics.h" +#define INCLUDE_FONTDATA +#include "font.h" + +TPT_INLINE void VideoBuffer::BlendPixel(int x, int y, int r, int g, int b, int a) +{ +#ifdef PIX32OGL + pixel t; + if (x<0 || y<0 || x>=Width || y>=Height) + return; + if (a!=255) + { + t = Buffer[y*(Width)+x]; + r = (a*r + (255-a)*PIXR(t)) >> 8; + g = (a*g + (255-a)*PIXG(t)) >> 8; + b = (a*b + (255-a)*PIXB(t)) >> 8; + a = a > PIXA(t) ? a : PIXA(t); + } + Buffer[y*(Width)+x] = PIXRGBA(r,g,b,a); +#else + pixel t; + if (x<0 || y<0 || x>=Width || y>=Height) + return; + if (a!=255) + { + t = Buffer[y*(Width)+x]; + r = (a*r + (255-a)*PIXR(t)) >> 8; + g = (a*g + (255-a)*PIXG(t)) >> 8; + b = (a*b + (255-a)*PIXB(t)) >> 8; + } + Buffer[y*(Width)+x] = PIXRGB(r,g,b); +#endif +} + +TPT_INLINE void VideoBuffer::SetPixel(int x, int y, int r, int g, int b, int a) +{ + if (x<0 || y<0 || x>=Width || y>=Height) + return; +#ifdef PIX32OGL + Buffer[y*(Width)+x] = PIXRGBA(r,g,b,a); +#else + Buffer[y*(Width)+x] = PIXRGB(r,g,b); +#endif +} + +TPT_INLINE void VideoBuffer::AddPixel(int x, int y, int r, int g, int b, int a) +{ + pixel t; + if (x<0 || y<0 || x>=Width || y>=Height) + return; + t = Buffer[y*(Width)+x]; + r = (a*r + 255*PIXR(t)) >> 8; + g = (a*g + 255*PIXG(t)) >> 8; + b = (a*b + 255*PIXB(t)) >> 8; + if (r>255) + r = 255; + if (g>255) + g = 255; + if (b>255) + b = 255; + Buffer[y*(Width)+x] = PIXRGB(r,g,b); +} + +TPT_INLINE int VideoBuffer::SetCharacter(int x, int y, int c, int r, int g, int b, int a) +{ + int i, j, w, bn = 0, ba = 0; + char *rp = font_data + font_ptrs[c]; + w = *(rp++); + for (j=0; j>= 2; + bn -= 2; + } + return x + w; +} + +TPT_INLINE int VideoBuffer::BlendCharacter(int x, int y, int c, int r, int g, int b, int a) +{ + int i, j, w, bn = 0, ba = 0; + char *rp = font_data + font_ptrs[c]; + w = *(rp++); + for (j=0; j>= 2; + bn -= 2; + } + return x + w; +} + +TPT_INLINE int VideoBuffer::AddCharacter(int x, int y, int c, int r, int g, int b, int a) +{ + int i, j, w, bn = 0, ba = 0; + char *rp = font_data + font_ptrs[c]; + w = *(rp++); + for (j=0; j>= 2; + bn -= 2; + } + return x + w; +} + +/** + * Common graphics functions, mostly static methods that provide + * encoding/decoding of different formats and font metrics + */ + +char * Graphics::GenerateGradient(pixel * colours, float * points, int pointcount, int size) +{ + int cp, i, j; + pixel ptemp; + char * newdata = (char*)malloc(size * 3); + float poss, pose, temp; + memset(newdata, 0, size*3); + //Sort the Colours and Points + for (i = (pointcount - 1); i > 0; i--) + { + for (j = 1; j <= i; j++) + { + if (points[j-1] > points[j]) + { + temp = points[j-1]; + points[j-1] = points[j]; + points[j] = temp; + + ptemp = colours[j-1]; + colours[j-1] = colours[j]; + colours[j] = ptemp; + } + } + } + i = 0; + j = 1; + poss = points[i]; + pose = points[j]; + for (cp = 0; cp < size; cp++) + { + float cpos = (float)cp / (float)size, ccpos, cccpos; + if(cpos > pose && j+1 < pointcount) + { + poss = points[++i]; + pose = points[++j]; + } + ccpos = cpos - poss; + cccpos = ccpos / (pose - poss); + if(cccpos > 1.0f) + cccpos = 1.0f; + newdata[(cp*3)] = PIXR(colours[i])*(1.0f-cccpos) + PIXR(colours[j])*(cccpos); + newdata[(cp*3)+1] = PIXG(colours[i])*(1.0f-cccpos) + PIXG(colours[j])*(cccpos); + newdata[(cp*3)+2] = PIXB(colours[i])*(1.0f-cccpos) + PIXB(colours[j])*(cccpos); + } + return newdata; +} + +void *Graphics::ptif_pack(pixel *src, int w, int h, int *result_size){ + int i = 0, datalen = (w*h)*3, cx = 0, cy = 0; + unsigned char *red_chan = (unsigned char*)calloc(1, w*h); + unsigned char *green_chan = (unsigned char*)calloc(1, w*h); + unsigned char *blue_chan = (unsigned char*)calloc(1, w*h); + unsigned char *data = (unsigned char*)malloc(((w*h)*3)+8); + unsigned char *result = (unsigned char*)malloc(((w*h)*3)+8); + + for(cx = 0; cx>8; + result[6] = h; + result[7] = h>>8; + + i -= 8; + + if(BZ2_bzBuffToBuffCompress((char *)(result+8), (unsigned *)&i, (char *)data, datalen, 9, 0, 0) != 0){ + free(data); + free(result); + return NULL; + } + + *result_size = i+8; + free(data); + return result; +} + +pixel *Graphics::ptif_unpack(void *datain, int size, int *w, int *h){ + int width, height, i, cx, cy, resCode; + unsigned char *red_chan; + unsigned char *green_chan; + unsigned char *blue_chan; + unsigned char *data = (unsigned char*)datain; + unsigned char *undata; + pixel *result; + if(size<16){ + printf("Image empty\n"); + return NULL; + } + if(!(data[0]=='P' && data[1]=='T' && data[2]=='i')){ + printf("Image header invalid\n"); + return NULL; + } + width = data[4]|(data[5]<<8); + height = data[6]|(data[7]<<8); + + i = (width*height)*3; + undata = (unsigned char*)calloc(1, (width*height)*3); + red_chan = (unsigned char*)calloc(1, width*height); + green_chan = (unsigned char*)calloc(1, width*height); + blue_chan = (unsigned char *)calloc(1, width*height); + result = (pixel *)calloc(width*height, PIXELSIZE); + + resCode = BZ2_bzBuffToBuffDecompress((char *)undata, (unsigned *)&i, (char *)(data+8), size-8, 0, 0); + if (resCode){ + printf("Decompression failure, %d\n", resCode); + free(red_chan); + free(green_chan); + free(blue_chan); + free(undata); + free(result); + return NULL; + } + if(i != (width*height)*3){ + printf("Result buffer size mismatch, %d != %d\n", i, (width*height)*3); + free(red_chan); + free(green_chan); + free(blue_chan); + free(undata); + free(result); + return NULL; + } + memcpy(red_chan, undata, width*height); + memcpy(green_chan, undata+(width*height), width*height); + memcpy(blue_chan, undata+((width*height)*2), width*height); + + for(cx = 0; cx sw && rh > sh){ + float fx, fy, fyc, fxc; + double intp; + pixel tr, tl, br, bl; + q = (pixel *)malloc(rw*rh*PIXELSIZE); + //Bilinear interpolation for upscaling + for (y=0; y=sw) fxceil = sw-1; + if (fyceil>=sh) fyceil = sh-1; + tr = src[sw*(int)floor(fy)+fxceil]; + tl = src[sw*(int)floor(fy)+(int)floor(fx)]; + br = src[sw*fyceil+fxceil]; + bl = src[sw*fyceil+(int)floor(fx)]; + q[rw*y+x] = PIXRGB( + (int)(((((float)PIXR(tl))*(1.0f-fxc))+(((float)PIXR(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXR(bl))*(1.0f-fxc))+(((float)PIXR(br))*(fxc)))*(fyc)), + (int)(((((float)PIXG(tl))*(1.0f-fxc))+(((float)PIXG(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXG(bl))*(1.0f-fxc))+(((float)PIXG(br))*(fxc)))*(fyc)), + (int)(((((float)PIXB(tl))*(1.0f-fxc))+(((float)PIXB(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXB(bl))*(1.0f-fxc))+(((float)PIXB(br))*(fxc)))*(fyc)) + ); + } + } else { + //Stairstepping + float fx, fy, fyc, fxc; + double intp; + pixel tr, tl, br, bl; + int rrw = rw, rrh = rh; + pixel * oq; + oq = (pixel *)malloc(sw*sh*PIXELSIZE); + memcpy(oq, src, sw*sh*PIXELSIZE); + rw = sw; + rh = sh; + while(rrw != rw && rrh != rh){ + rw *= 0.7; + rh *= 0.7; + if(rw <= rrw || rh <= rrh){ + rw = rrw; + rh = rrh; + } + q = (pixel *)malloc(rw*rh*PIXELSIZE); + //Bilinear interpolation for upscaling + for (y=0; y=sw) fxceil = sw-1; + if (fyceil>=sh) fyceil = sh-1; + tr = oq[sw*(int)floor(fy)+fxceil]; + tl = oq[sw*(int)floor(fy)+(int)floor(fx)]; + br = oq[sw*fyceil+fxceil]; + bl = oq[sw*fyceil+(int)floor(fx)]; + q[rw*y+x] = PIXRGB( + (int)(((((float)PIXR(tl))*(1.0f-fxc))+(((float)PIXR(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXR(bl))*(1.0f-fxc))+(((float)PIXR(br))*(fxc)))*(fyc)), + (int)(((((float)PIXG(tl))*(1.0f-fxc))+(((float)PIXG(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXG(bl))*(1.0f-fxc))+(((float)PIXG(br))*(fxc)))*(fyc)), + (int)(((((float)PIXB(tl))*(1.0f-fxc))+(((float)PIXB(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXB(bl))*(1.0f-fxc))+(((float)PIXB(br))*(fxc)))*(fyc)) + ); + } + free(oq); + oq = q; + sw = rw; + sh = rh; + } + } + return q; +} + +pixel *Graphics::rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f) +{ + int i,j,x,y,w,h,r,g,b,c; + pixel p, *q; + w = (sw+f-1)/f; + h = (sh+f-1)/f; + q = (pixel *)malloc(w*h*PIXELSIZE); + for (y=0; y1) + { + r = (r+c/2)/c; + g = (g+c/2)/c; + b = (b+c/2)/c; + } + q[y*w+x] = PIXRGB(r, g, b); + } + *qw = w; + *qh = h; + return q; +} + +int Graphics::textwidth(const char *s) +{ + int x = 0; + for (; *s; s++) + x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + return x-1; +} + +int Graphics::textnwidth(char *s, int n) +{ + int x = 0; + for (; *s; s++) + { + if (!n) + break; + if(((char)*s)=='\b') + { + if(!s[1]) break; + s++; + continue; + } else if(*s == '\x0F') { + if(!s[1] || !s[2] || !s[3]) break; + s+=3; + continue; + } + x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + n--; + } + return x-1; +} + +void Graphics::textnpos(char *s, int n, int w, int *cx, int *cy) +{ + int x = 0; + int y = 0; + int wordlen, charspace; + while (*s&&n) + { + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, w-x); + if (charspace=-1; s++) + { + if (!n) { + break; + } + x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if (x>=w) + { + x = 0; + y += FONT_H+2; + } + n--; + } + } + *cx = x-1; + *cy = y; +} + +int Graphics::textwidthx(char *s, int w) +{ + int x=0,n=0,cw; + for (; *s; s++) + { + if((char)*s == '\b') + { + if(!s[1]) break; + s++; + continue; + } else if (*s == '\x0F') + { + if(!s[1] || !s[2] || !s[3]) break; + s+=3; + continue; + } + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if (x+(cw/2) >= w) + break; + x += cw; + n++; + } + return n; +} + +int Graphics::PositionAtCharIndex(char *s, int charIndex, int & positionX, int & positionY) +{ + int x = 0, y = 0, lines = 1; + for (; *s; s++) + { + if (!charIndex) + break; + if(*s == '\n') { + lines++; + x = 0; + y += FONT_H+2; + charIndex--; + continue; + } else if(*s =='\b') { + if(!s[1]) break; + s++; + charIndex-=2; + continue; + } else if(*s == '\x0F') { + if(!s[1] || !s[2] || !s[3]) break; + s+=3; + charIndex-=4; + continue; + } + x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + charIndex--; + } + positionX = x; + positionY = y; + return lines; +} + +int Graphics::CharIndexAtPosition(char *s, int positionX, int positionY) +{ + int x=0, y=0,charIndex=0,cw; + for (; *s; s++) + { + if(*s == '\n') { + x = 0; + y += FONT_H+2; + charIndex++; + continue; + } else if(*s == '\b') { + if(!s[1]) break; + s++; + charIndex+=2; + continue; + } else if (*s == '\x0F') { + if(!s[1] || !s[2] || !s[3]) break; + s+=3; + charIndex+=4; + continue; + } + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if ((x+(cw/2) >= positionX && y+FONT_H >= positionY) || y > positionY) + break; + x += cw; + charIndex++; + } + return charIndex; +} + + +int Graphics::textposxy(char *s, int width, int w, int h) +{ + int x=0,y=0,n=0,cw, wordlen, charspace; + while (*s) + { + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, width-x); + if (charspace=-1; s++) + { + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if ((x+(cw/2) >= w && y+6 >= h)||(y+6 >= h+FONT_H+2)) + return n++; + x += cw; + if (x>=width) { + x = 0; + y += FONT_H+2; + } + n++; + } + } + return n; +} +int Graphics::textwrapheight(char *s, int width) +{ + int x=0, height=FONT_H+2, cw; + int wordlen; + int charspace; + while (*s) + { + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, width-x); + if (charspace=-1; s++) + { + if (*s == '\n') + { + x = 0; + height += FONT_H+2; + } + else if (*s == '\b') + { + if(!s[1]) break; + s++; + } + else if (*s == '\x0F') + { + if(!s[1] || !s[2] || !s[3]) break; + s+=3; + } + else + { + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if (x+cw>=width) + { + x = 0; + height += FONT_H+2; + } + x += cw; + } + } + } + return height; +} + +void Graphics::textsize(const char * s, int & width, int & height) +{ + if(!strlen(s)) + { + width = 0; + height = FONT_H; + return; + } + + int cHeight = FONT_H, cWidth = 0, lWidth = 0; + for (; *s; s++) + { + if (*s == '\n') + { + cWidth = 0; + cHeight += FONT_H+2; + } + else if (*s == '\x0F') + { + if(!s[1] || !s[2] || !s[1]) break; + s+=3; + } + else if (*s == '\b') + { + if(!s[1]) break; + s++; + } + else + { + cWidth += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if(cWidth>lWidth) + lWidth = cWidth; + } + } + width = lWidth; + height = cHeight; +} + +void Graphics::draw_icon(int x, int y, Icon icon) +{ + y--; + switch(icon) + { + case IconOpen: + drawchar(x, y, 0x81, 255, 255, 255, 255); + break; + case IconReload: + drawchar(x, y, 0x91, 255, 255, 255, 255); + break; + case IconSave: + drawchar(x, y, 0x82, 255, 255, 255, 255); + break; + case IconVoteUp: + drawchar(x, y, 0xCB, 0, 187, 18, 255); + break; + case IconVoteDown: + drawchar(x, y, 0xCA, 187, 40, 0, 255); + break; + case IconTag: + drawchar(x, y, 0x83, 255, 255, 255, 255); + break; + case IconNew: + drawchar(x, y, 0x92, 255, 255, 255, 255); + break; + case IconLogin: + drawchar(x, y, 0x84, 255, 255, 255, 255); + break; + case IconSimulationSettings: + drawchar(x, y, 0xCF, 255, 255, 255, 255); + break; + case IconRenderSettings: + addchar(x, y, 0xD8, 255, 0, 0, 255); + addchar(x, y, 0xD9, 0, 255, 0, 255); + addchar(x, y, 0xDA, 0, 0, 255, 255); + break; + case IconPause: + drawchar(x, y, 0x90, 255, 255, 255, 255); + break; + case IconFavourite: + drawchar(x, y, 0xCC, 192, 160, 64, 255); + break; + case IconReport: + drawchar(x, y, 0xE3, 255, 255, 0, 255); + break; + case IconUsername: + drawchar(x, y, 0x8B, 32, 64, 128, 255); + drawchar(x, y, 0x8A, 255, 255, 255, 255); + break; + case IconPassword: + drawchar(x, y, 0x8C, 160, 144, 32, 255); + drawchar(x, y, 0x84, 255, 255, 255, 255); + break; + case IconClose: + drawchar(x, y, 0xAA, 230, 230, 230, 255); + break; + case IconVoteSort: + case IconDateSort: + case IconFolder: + case IconSearch: + case IconDelete: + drawchar(x, y, 0x86, 255, 55, 55, 255); + drawchar(x, y, 0x85, 255, 255, 255, 255); + break; + default: + drawchar(x, y, 't', 255, 255, 255, 255); + break; + } +} + +pixel *Graphics::render_packed_rgb(void *image, int width, int height, int cmp_size) +{ + unsigned char *tmp; + pixel *res; + int i; + + tmp = (unsigned char *)malloc(width*height*3); + if (!tmp) + return NULL; + res = (pixel *)malloc(width*height*PIXELSIZE); + if (!res) + { + free(tmp); + return NULL; + } + + i = width*height*3; + if (BZ2_bzBuffToBuffDecompress((char *)tmp, (unsigned *)&i, (char *)image, cmp_size, 0, 0)) + { + free(res); + free(tmp); + return NULL; + } + + for (i=0; i +#include +#include +#if defined(OGLI) +#include "OpenGLHeaders.h" +#endif +#include "Config.h" +//#include "powder.h" + +#ifdef PIX16 +#define PIXELSIZE 2 +#define PIXPACK(x) ((((x)>>8)&0xF800)|(((x)>>5)&0x07E0)|(((x)>>3)&0x001F)) +#define PIXRGB(r,g,b) ((((r)<<8)&0xF800)|(((g)<<3)&0x07E0)|(((b)>>3)&0x001F)) +#define PIXR(x) (((x)>>8)&0xF8) +#define PIXG(x) (((x)>>3)&0xFC) +#define PIXB(x) (((x)<<3)&0xF8) +#else +#define PIXELSIZE 4 +#ifdef PIX32BGR +#define PIXPACK(x) ((((x)>>16)&0x0000FF)|((x)&0x00FF00)|(((x)<<16)&0xFF0000)) +#define PIXRGB(r,g,b) (((b)<<16)|((g)<<8)|((r)))// (((b)<<16)|((g)<<8)|(r)) +#define PIXR(x) ((x)&0xFF) +#define PIXG(x) (((x)>>8)&0xFF) +#define PIXB(x) ((x)>>16) +#else +#ifdef PIX32BGRA +#define PIXPACK(x) ((((x)>>8)&0x0000FF00)|(((x)<<8)&0x00FF0000)|(((x)<<24)&0xFF000000)) +#define PIXRGB(r,g,b) (((b)<<24)|((g)<<16)|((r)<<8)) +#define PIXR(x) (((x)>>8)&0xFF) +#define PIXG(x) (((x)>>16)&0xFF) +#define PIXB(x) (((x)>>24)) +#elif defined(PIX32OGL) +#define PIXPACK(x) (0xFF000000|((x)&0xFFFFFF)) +#define PIXRGB(r,g,b) (0xFF000000|((r)<<16)|((g)<<8)|((b)))// (((b)<<16)|((g)<<8)|(r)) +#define PIXRGBA(r,g,b,a) (((a)<<24)|((r)<<16)|((g)<<8)|((b)))// (((b)<<16)|((g)<<8)|(r)) +#define PIXA(x) (((x)>>24)&0xFF) +#define PIXR(x) (((x)>>16)&0xFF) +#define PIXG(x) (((x)>>8)&0xFF) +#define PIXB(x) ((x)&0xFF) +#else +#define PIXPACK(x) (x) +#define PIXRGB(r,g,b) (((r)<<16)|((g)<<8)|(b)) +#define PIXR(x) ((x)>>16) +#define PIXG(x) (((x)>>8)&0xFF) +#define PIXB(x) ((x)&0xFF) +#endif +#endif +#endif + +#ifdef PIX16 +typedef unsigned short pixel; +#else +typedef unsigned int pixel; +#endif + +//Icon names, see Graphics::draw_icon +enum Icon +{ + NoIcon = 0, + IconOpen, + IconReload, + IconSave, + IconVoteUp, + IconVoteDown, + IconTag, + IconNew, + IconLogin, + IconRenderSettings, + IconSimulationSettings, + IconPause, + IconVoteSort, + IconDateSort, + IconFavourite, + IconFolder, + IconSearch, + IconDelete, + IconReport, + IconUsername, + IconPassword, + IconClose +}; + +//"Graphics lite" - slightly lower performance due to variable size, +class VideoBuffer +{ +public: + pixel * Buffer; + int Width, Height; + + VideoBuffer(int width, int height): Width(width), Height(height), Buffer((pixel*)calloc(width*height, PIXELSIZE)) { }; + void BlendPixel(int x, int y, int r, int g, int b, int a); + void AddPixel(int x, int y, int r, int g, int b, int a); + void SetPixel(int x, int y, int r, int g, int b, int a); + int BlendCharacter(int x, int y, int c, int r, int g, int b, int a); + int AddCharacter(int x, int y, int c, int r, int g, int b, int a); + int SetCharacter(int x, int y, int c, int r, int g, int b, int a); + ~VideoBuffer() { free(Buffer); }; +}; + +class Graphics +{ +public: + pixel *vid; + int sdl_scale; +#ifdef OGLI + //OpenGL specific instance variables + GLuint vidBuf, textTexture; + void Reset(); + #endif + + //Common graphics methods in Graphics.cpp + static char * GenerateGradient(pixel * colours, float * points, int pointcount, int size); + + //PTIF methods + static void *ptif_pack(pixel *src, int w, int h, int *result_size); + static pixel *ptif_unpack(void *datain, int size, int *w, int *h); + static pixel *resample_img_nn(pixel *src, int sw, int sh, int rw, int rh); + static pixel *resample_img(pixel *src, int sw, int sh, int rw, int rh); + static pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f); + static pixel *render_packed_rgb(void *image, int width, int height, int cmp_size); + + //Font/text metrics + static int CharIndexAtPosition(char *s, int positionX, int positionY); + static int PositionAtCharIndex(char *s, int charIndex, int & positionX, int & positionY); + static int textnwidth(char *s, int n); + static void textnpos(char *s, int n, int w, int *cx, int *cy); + static int textwidthx(char *s, int w); + static int textposxy(char *s, int width, int w, int h); + static int textwrapheight(char *s, int width); + static int textwidth(const char *s); + static void textsize(const char * s, int & width, int & height); + + void blendpixel(int x, int y, int r, int g, int b, int a); + void addpixel(int x, int y, int r, int g, int b, int a); + + void draw_icon(int x, int y, Icon icon); + + void Clear(); + void Finalise(); + // + int drawtext(int x, int y, const char *s, int r, int g, int b, int a); + int drawtext(int x, int y, std::string s, int r, int g, int b, int a); + int drawchar(int x, int y, int c, int r, int g, int b, int a); + int addchar(int x, int y, int c, int r, int g, int b, int a); + + void xor_pixel(int x, int y); + void xor_line(int x, int y, int x2, int y2); + void xor_rect(int x, int y, int width, int height); + void xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h); + + void draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a); + void drawrect(int x, int y, int width, int height, int r, int g, int b, int a); + void fillrect(int x, int y, int width, int height, int r, int g, int b, int a); + void clearrect(int x, int y, int width, int height); + void gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2); + + void draw_image(pixel *img, int x, int y, int w, int h, int a); + + Graphics(); + ~Graphics(); +}; + +#endif diff --git a/src/graphics/OpenGLDrawMethods.inc b/src/graphics/OpenGLDrawMethods.inc new file mode 100644 index 0000000..cd1a350 --- /dev/null +++ b/src/graphics/OpenGLDrawMethods.inc @@ -0,0 +1,331 @@ +int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a) +{ + if(!strlen(s)) + return 0; + int oR = r, oG = g, oB = b; + int width, height; + Graphics::textsize(s, width, height); + VideoBuffer texture(width, height); + int characterX = 0, characterY = 0; + int startX = characterX; + for (; *s; s++) + { + if (*s == '\n') + { + characterX = startX; + characterY += FONT_H+2; + } + else if (*s == '\x0F') + { + if(!s[1] || !s[2] || !s[3]) break; + r = s[1]; + g = s[2]; + b = s[3]; + s += 3; + } + else if (*s == '\x0E') + { + r = oR; + g = oG; + b = oB; + } + else if (*s == '\b') + { + if(!s[1]) break; + switch (s[1]) + { + case 'w': + r = g = b = 255; + break; + case 'g': + r = g = b = 192; + break; + case 'o': + r = 255; + g = 216; + b = 32; + break; + case 'r': + r = 255; + g = b = 0; + break; + case 'l': + r = 255; + g = b = 75; + break; + case 'b': + r = g = 0; + b = 255; + break; + case 't': + b = 255; + g = 170; + r = 32; + break; + } + s++; + } + else + { + characterX = texture.SetCharacter(characterX, characterY, *(unsigned char *)s, r, g, b, a); + } + } + glEnable(GL_TEXTURE_2D); + + //Generate texture + glBindTexture(GL_TEXTURE_2D, textTexture); + + //Draw texture + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.Width, texture.Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, texture.Buffer); + + //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture.Width, texture.Height, GL_BGRA, GL_UNSIGNED_BYTE, texture.Buffer); + glBegin(GL_QUADS); + glTexCoord2d(0, 0); + glVertex2f(x, y); + glTexCoord2d(1, 0); + glVertex2f(x+texture.Width, y); + glTexCoord2d(1, 1); + glVertex2f(x+texture.Width, y+texture.Height); + glTexCoord2d(0, 1); + glVertex2f(x, y+texture.Height); + glEnd(); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + return x; +} + +int Graphics::drawtext(int x, int y, std::string s, int r, int g, int b, int a) +{ + return drawtext(x, y, s.c_str(), r, g, b, a); +} + +TPT_INLINE int Graphics::drawchar(int x, int y, int c, int r, int g, int b, int a) +{ + int i, j, w, bn = 0, ba = 0; + char *rp = font_data + font_ptrs[c]; + w = *(rp++); + VideoBuffer texture(w, 12); + texture.SetCharacter(0, 0, c, r, g, b, a); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, textTexture); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.Width, texture.Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, texture.Buffer); + glBegin(GL_QUADS); + glTexCoord2d(0, 0); + glVertex2f(x, y); + glTexCoord2d(1, 0); + glVertex2f(x+texture.Width, y); + glTexCoord2d(1, 1); + glVertex2f(x+texture.Width, y+texture.Height); + glTexCoord2d(0, 1); + glVertex2f(x, y+texture.Height); + glEnd(); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + return x + w; +} + +TPT_INLINE int Graphics::addchar(int x, int y, int c, int r, int g, int b, int a) +{ + int i, j, w, bn = 0, ba = 0; + char *rp = font_data + font_ptrs[c]; + w = *(rp++); + VideoBuffer texture(w, 12); + texture.AddCharacter(0, 0, c, r, g, b, a); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, textTexture); + glBlendFunc(GL_ONE, GL_ONE); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.Width, texture.Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, texture.Buffer); + glBegin(GL_QUADS); + glTexCoord2d(0, 0); + glVertex2f(x, y); + glTexCoord2d(1, 0); + glVertex2f(x+texture.Width, y); + glTexCoord2d(1, 1); + glVertex2f(x+texture.Width, y+texture.Height); + glTexCoord2d(0, 1); + glVertex2f(x, y+texture.Height); + glEnd(); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + return x + w; +} + +TPT_INLINE void Graphics::xor_pixel(int x, int y) +{ + //OpenGL doesn't support single pixel manipulation, there are ways around it, but with poor performance +} + +TPT_INLINE void Graphics::blendpixel(int x, int y, int r, int g, int b, int a) +{ + //OpenGL doesn't support single pixel manipulation, there are ways around it, but with poor performance +} + +TPT_INLINE void Graphics::addpixel(int x, int y, int r, int g, int b, int a) +{ + //OpenGL doesn't support single pixel manipulation, there are ways around it, but with poor performance +} + +void Graphics::xor_line(int x, int y, int x2, int y2) +{ + glEnable(GL_COLOR_LOGIC_OP); + //glEnable(GL_LINE_SMOOTH); + glLogicOp(GL_XOR); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glBegin(GL_LINES); + glVertex2i(x, y); + glVertex2i(x2, y2); + glEnd(); + glDisable(GL_COLOR_LOGIC_OP); +} + +void Graphics::xor_rect(int x, int y, int width, int height) +{ + glEnable(GL_COLOR_LOGIC_OP); + //glEnable(GL_LINE_SMOOTH); + glLogicOp(GL_XOR); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x+width, y); + glVertex2i(x+width, y+height); + glVertex2i(x, y+height); + glVertex2i(x, y); + glEnd(); + glDisable(GL_COLOR_LOGIC_OP); +} + +void Graphics::xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h) +{ + //glEnable(GL_COLOR_LOGIC_OP); + //glLogicOp(GL_XOR); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, textTexture); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap); + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + + glBegin(GL_QUADS); + glTexCoord2d(0, 0); + glVertex2f(x, y); + glTexCoord2d(1, 0); + glVertex2f(x+w, y); + glTexCoord2d(1, 1); + glVertex2f(x+w, y+h); + glTexCoord2d(0, 1); + glVertex2f(x, y+h); + glEnd(); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + //glDisable(GL_COLOR_LOGIC_OP); +} + +void Graphics::draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a) +{ + a = 255; + glColor4ub(r, g, b, a); + glBegin(GL_LINES); + glVertex2i(x, y); + glVertex2i(x2, y2); + glEnd(); +} + +void Graphics::drawrect(int x, int y, int width, int height, int r, int g, int b, int a) +{ + float fx = float(x)+0.5f; + float fy = float(y)+0.5f; + float fwidth = width-1.0f; + float fheight = height-1.0f; + //x++; + //y++; + //height-=2; + //width-=2; + glColor4ub(r, g, b, a); + glBegin(GL_LINE_STRIP); + glVertex2f(fx, fy); + glVertex2f(fx+fwidth, fy); + glVertex2f(fx+fwidth, fy+fheight); + glVertex2f(fx, fy+fheight); //+1 is a hack to prevent squares from missing their corners, will make smoothed lines look like SHIT + glVertex2f(fx, fy); + glEnd(); +} + +void Graphics::fillrect(int x, int y, int width, int height, int r, int g, int b, int a) +{ + /*x++; + y++; + width-=1; + height-=1;*/ + + glColor4ub(r, g, b, a); + glBegin(GL_QUADS); + glVertex2i(x, y); + glVertex2i(x+width, y); + glVertex2i(x+width, y+height); + glVertex2i(x, y+height); + glEnd(); +} + +void Graphics::gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2) +{ + glBegin(GL_QUADS); + glColor4ub(r, g, b, a); + glVertex2i(x, y); + glColor4ub(r2, g2, b2, a2); + glVertex2i(x+width, y); + glColor4ub(r2, g2, b2, a2); + glVertex2i(x+width, y+height); + glColor4ub(r, g, b, a); + glVertex2i(x, y+height); + glEnd(); +} + +void Graphics::clearrect(int x, int y, int width, int height) +{ + glColor4ub(0, 0, 0, 255); + glBegin(GL_QUADS); + glVertex2i(x, y); + glVertex2i(x+width, y); + glVertex2i(x+width, y+height); + glVertex2i(x, y+height); + glEnd(); +} + +void Graphics::draw_image(pixel *img, int x, int y, int w, int h, int a) +{ + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, textTexture); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, img); + glBegin(GL_QUADS); + glTexCoord2d(0, 0); + glVertex2f(x, y); + glTexCoord2d(1, 0); + glVertex2f(x+w, y); + glTexCoord2d(1, 1); + glVertex2f(x+w, y+h); + glTexCoord2d(0, 1); + glVertex2f(x, y+h); + glEnd(); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); +} \ No newline at end of file diff --git a/src/graphics/OpenGLGraphics.cpp b/src/graphics/OpenGLGraphics.cpp new file mode 100644 index 0000000..baef250 --- /dev/null +++ b/src/graphics/OpenGLGraphics.cpp @@ -0,0 +1,78 @@ +#include "Graphics.h" +#include "font.h" + +#ifdef OGLI + +Graphics::Graphics(): +sdl_scale(1) +{ + Reset(); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + //Texture for main UI + glEnable(GL_TEXTURE_2D); + + glGenTextures(1, &vidBuf); + glBindTexture(GL_TEXTURE_2D, vidBuf); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, XRES+BARSIZE, YRES+MENUSIZE, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + + glBindTexture(GL_TEXTURE_2D, 0); + + glGenTextures(1, &textTexture); + glBindTexture(GL_TEXTURE_2D, textTexture); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glBindTexture(GL_TEXTURE_2D, 0); + + glDisable(GL_TEXTURE_2D); +} + +Graphics::~Graphics() +{ +} + +void Graphics::Reset() +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + //glOrtho(0, (XRES+BARSIZE)*sdl_scale, 0, (YRES+MENUSIZE)*sdl_scale, -1, 1); + glOrtho(0, (XRES+BARSIZE)*sdl_scale, (YRES+MENUSIZE)*sdl_scale, 0, -1, 1); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + //glRasterPos2i(0, (YRES+MENUSIZE)); + glRasterPos2i(0, 0); + glPixelZoom(1, 1); +} + +void Graphics::Clear() +{ + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); +} + +void Graphics::Finalise() +{ + glFlush(); +} + +#define VIDXRES XRES+BARSIZE +#define VIDYRES YRES+MENUSIZE +#define PIXELMETHODS_CLASS Graphics +#include "OpenGLDrawMethods.inc" +#undef VIDYRES +#undef VIDXRES +#undef PIXELMETHODS_CLASS + + +#endif diff --git a/src/graphics/OpenGLHeaders.h b/src/graphics/OpenGLHeaders.h new file mode 100644 index 0000000..8a83472 --- /dev/null +++ b/src/graphics/OpenGLHeaders.h @@ -0,0 +1,24 @@ +#ifdef MACOSX + +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +#include +#include +#else +//#include +#include +#include +#define GL_RGBA32F 0x8814 +#endif + +#elif defined(WIN32) + +#include +#include +#include + +#else + +#include +#include +#include +#endif diff --git a/src/graphics/RasterDrawMethods.inc b/src/graphics/RasterDrawMethods.inc new file mode 100644 index 0000000..4d85f60 --- /dev/null +++ b/src/graphics/RasterDrawMethods.inc @@ -0,0 +1,348 @@ +#include "font.h" + +int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int b, int a) +{ + if(!strlen(s)) + return 0; + int width, height; + + int oR = r, oG = g, oB = b; + int characterX = x, characterY = y; + int startX = characterX; + for (; *s; s++) + { + if (*s == '\n') + { + characterX = startX; + characterY += FONT_H+2; + } + else if (*s == '\x0F') + { + if(!s[1] || !s[2] || !s[3]) break; + r = s[1]; + g = s[2]; + b = s[3]; + s += 3; + } + else if (*s == '\x0E') + { + r = oR; + g = oG; + b = oB; + } + else if (*s == '\b') + { + if(!s[1]) break; + switch (s[1]) + { + case 'w': + r = g = b = 255; + break; + case 'g': + r = g = b = 192; + break; + case 'o': + r = 255; + g = 216; + b = 32; + break; + case 'r': + r = 255; + g = b = 0; + break; + case 'l': + r = 255; + g = b = 75; + break; + case 'b': + r = g = 0; + b = 255; + break; + case 't': + b = 255; + g = 170; + r = 32; + break; + } + s++; + } + else + { + characterX = drawchar(characterX, characterY, *(unsigned char *)s, r, g, b, a); + } + } + return x; +} + +int PIXELMETHODS_CLASS::drawtext(int x, int y, std::string s, int r, int g, int b, int a) +{ + return drawtext(x, y, s.c_str(), r, g, b, a); +} + +TPT_INLINE int PIXELMETHODS_CLASS::drawchar(int x, int y, int c, int r, int g, int b, int a) +{ + int i, j, w, bn = 0, ba = 0; + char *rp = font_data + font_ptrs[c]; + w = *(rp++); + for (j=0; j>= 2; + bn -= 2; + } + return x + w; +} + +TPT_INLINE int PIXELMETHODS_CLASS::addchar(int x, int y, int c, int r, int g, int b, int a) +{ + int i, j, w, bn = 0, ba = 0; + char *rp = font_data + font_ptrs[c]; + w = *(rp++); + for (j=0; j>= 2; + bn -= 2; + } + return x + w; +} + +TPT_INLINE void PIXELMETHODS_CLASS::xor_pixel(int x, int y) +{ + int c; + if (x<0 || y<0 || x>=XRES || y>=YRES) + return; + c = vid[y*(VIDXRES)+x]; + c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c); + if (c<512) + vid[y*(VIDXRES)+x] = PIXPACK(0xC0C0C0); + else + vid[y*(VIDXRES)+x] = PIXPACK(0x404040); +} + +TPT_INLINE void PIXELMETHODS_CLASS::blendpixel(int x, int y, int r, int g, int b, int a) +{ + pixel t; + if (x<0 || y<0 || x>=VIDXRES || y>=VIDYRES) + return; + if (a!=255) + { + t = vid[y*(VIDXRES)+x]; + r = (a*r + (255-a)*PIXR(t)) >> 8; + g = (a*g + (255-a)*PIXG(t)) >> 8; + b = (a*b + (255-a)*PIXB(t)) >> 8; + } + vid[y*(VIDXRES)+x] = PIXRGB(r,g,b); +} + +TPT_INLINE void PIXELMETHODS_CLASS::addpixel(int x, int y, int r, int g, int b, int a) +{ + pixel t; + if (x<0 || y<0 || x>=VIDXRES || y>=VIDYRES) + return; + t = vid[y*(VIDXRES)+x]; + r = (a*r + 255*PIXR(t)) >> 8; + g = (a*g + 255*PIXG(t)) >> 8; + b = (a*b + 255*PIXB(t)) >> 8; + if (r>255) + r = 255; + if (g>255) + g = 255; + if (b>255) + b = 255; + vid[y*(VIDXRES)+x] = PIXRGB(r,g,b); +} + +void PIXELMETHODS_CLASS::xor_line(int x1, int y1, int x2, int y2) +{ + int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; + float e, de; + if (cp) + { + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if (x1 > x2) + { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + if (dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1= 0.5f) + { + y += sy; + e -= 1.0f; + } + } +} + +void PIXELMETHODS_CLASS::xor_rect(int x, int y, int w, int h) +{ + int i; + for (i=0; iabs(x2-x1), x, y, dx, dy, sy; + float e, de; + if (cp) + { + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if (x1 > x2) + { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + if (dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1= 0.5f) + { + y += sy; + e -= 1.0f; + } + } +} + +void PIXELMETHODS_CLASS::drawrect(int x, int y, int w, int h, int r, int g, int b, int a) +{ + int i; + w--; + h--; + for (i=0; i<=w; i++) + { + blendpixel(x+i, y, r, g, b, a); + blendpixel(x+i, y+h, r, g, b, a); + } + for (i=1; i VIDYRES) h = (VIDYRES)-y; //Adjust height to prevent drawing off the bottom + if(a >= 255) + for (j=0; j +#include +#include +#include +#include +#include "Config.h" +#include "Renderer.h" +#include "Graphics.h" +#include "simulation/Elements.h" +#include "simulation/ElementGraphics.h" +#include "simulation/Air.h" +extern "C" +{ +#include "hmap.h" +#ifdef OGLR +#include "Shaders.h" +#endif +} + +#ifndef OGLI +#define VIDXRES XRES+BARSIZE +#define VIDYRES YRES+MENUSIZE +#else +#define VIDXRES XRES +#define VIDYRES YRES +#endif + +#ifdef OGLR +#define drawrect(args) g->drawrect(args) +#endif + +void Renderer::clearScreen(float alpha) +{ +#ifdef OGLR + GLint prevFbo; + if(alpha > 0.999f) + { + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); + glClear(GL_COLOR_BUFFER_BIT); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); + } + else + { + glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); + glColor4f(1.0f, 1.0f, 1.0f, alpha); + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); + glBegin(GL_QUADS); + glVertex2f(0, 0); + glVertex2f(XRES, 0); + glVertex2f(XRES, YRES); + glVertex2f(0, YRES); + glEnd(); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); + glBlendEquation(GL_FUNC_ADD); + } + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); +#endif +#ifdef OGLI + std::fill(vid, vid+(VIDXRES*VIDYRES), 0); +#endif +} +#ifdef OGLR +void Renderer::checkShader(GLuint shader, char * shname) +{ + GLint status; + glGetShaderiv(shader, GL_COMPILE_STATUS, &status); + if (status == GL_FALSE) + { + char errorBuf[ GL_INFO_LOG_LENGTH]; + int errLen; + glGetShaderInfoLog(shader, GL_INFO_LOG_LENGTH, &errLen, errorBuf); + fprintf(stderr, "Failed to compile %s shader:\n%s\n", shname, errorBuf); + exit(1); + } +} +void Renderer::checkProgram(GLuint program, char * progname) +{ + GLint status; + glGetProgramiv(program, GL_LINK_STATUS, &status); + if (status == GL_FALSE) + { + char errorBuf[ GL_INFO_LOG_LENGTH]; + int errLen; + glGetShaderInfoLog(program, GL_INFO_LOG_LENGTH, &errLen, errorBuf); + fprintf(stderr, "Failed to link %s program:\n%s\n", progname, errorBuf); + exit(1); + } +} +void Renderer::loadShaders() +{ + GLuint vertexShader, fragmentShader; + + //Particle texture + vertexShader = glCreateShader(GL_VERTEX_SHADER); + fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); + + glShaderSource( vertexShader, 1, &fireVertex, NULL); + glShaderSource( fragmentShader, 1, &fireFragment, NULL); + + glCompileShader( vertexShader ); + checkShader(vertexShader, "FV"); + glCompileShader( fragmentShader ); + checkShader(fragmentShader, "FF"); + + fireProg = glCreateProgram(); + glAttachShader( fireProg, vertexShader ); + glAttachShader( fireProg, fragmentShader ); + glLinkProgram( fireProg ); + checkProgram(fireProg, "F"); + + //Lensing + vertexShader = glCreateShader(GL_VERTEX_SHADER); + fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); + + glShaderSource( vertexShader, 1, &lensVertex, NULL); + glShaderSource( fragmentShader, 1, &lensFragment, NULL); + + glCompileShader( vertexShader ); + checkShader(vertexShader, "LV"); + glCompileShader( fragmentShader ); + checkShader(fragmentShader, "LF"); + + lensProg = glCreateProgram(); + glAttachShader( lensProg, vertexShader ); + glAttachShader( lensProg, fragmentShader ); + glLinkProgram( lensProg ); + checkProgram(lensProg, "L"); + + //Air Velocity + vertexShader = glCreateShader(GL_VERTEX_SHADER); + fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); + + glShaderSource( vertexShader, 1, &airVVertex, NULL); + glShaderSource( fragmentShader, 1, &airVFragment, NULL); + + glCompileShader( vertexShader ); + checkShader(vertexShader, "AVX"); + glCompileShader( fragmentShader ); + checkShader(fragmentShader, "AVF"); + + airProg_Velocity = glCreateProgram(); + glAttachShader( airProg_Velocity, vertexShader ); + glAttachShader( airProg_Velocity, fragmentShader ); + glLinkProgram( airProg_Velocity ); + checkProgram(airProg_Velocity, "AV"); + + //Air Pressure + vertexShader = glCreateShader(GL_VERTEX_SHADER); + fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); + + glShaderSource( vertexShader, 1, &airPVertex, NULL); + glShaderSource( fragmentShader, 1, &airPFragment, NULL); + + glCompileShader( vertexShader ); + checkShader(vertexShader, "APV"); + glCompileShader( fragmentShader ); + checkShader(fragmentShader, "APF"); + + airProg_Pressure = glCreateProgram(); + glAttachShader( airProg_Pressure, vertexShader ); + glAttachShader( airProg_Pressure, fragmentShader ); + glLinkProgram( airProg_Pressure ); + checkProgram(airProg_Pressure, "AP"); + + //Air cracker + vertexShader = glCreateShader(GL_VERTEX_SHADER); + fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); + + glShaderSource( vertexShader, 1, &airCVertex, NULL); + glShaderSource( fragmentShader, 1, &airCFragment, NULL); + + glCompileShader( vertexShader ); + checkShader(vertexShader, "ACV"); + glCompileShader( fragmentShader ); + checkShader(fragmentShader, "ACF"); + + airProg_Cracker = glCreateProgram(); + glAttachShader( airProg_Cracker, vertexShader ); + glAttachShader( airProg_Cracker, fragmentShader ); + glLinkProgram( airProg_Cracker ); + checkProgram(airProg_Cracker, "AC"); +} +#endif + +void Renderer::FinaliseParts() +{ +#ifdef OGLR + glEnable( GL_TEXTURE_2D ); + if(display_mode & DISPLAY_WARP) + { + float xres = XRES, yres = YRES; + glUseProgram(lensProg); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, partsFboTex); + glUniform1i(glGetUniformLocation(lensProg, "pTex"), 0); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, partsTFX); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_RED, GL_FLOAT, sim->gravx); + glUniform1i(glGetUniformLocation(lensProg, "tfX"), 1); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, partsTFY); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_GREEN, GL_FLOAT, sim->gravy); + glUniform1i(glGetUniformLocation(lensProg, "tfY"), 2); + glActiveTexture(GL_TEXTURE0); + glUniform1fv(glGetUniformLocation(lensProg, "xres"), 1, &xres); + glUniform1fv(glGetUniformLocation(lensProg, "yres"), 1, &yres); + } + else + { + glBindTexture(GL_TEXTURE_2D, partsFboTex); + glBlendFunc(GL_ONE, GL_ONE); + } + + int sdl_scale = 1; + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2d(1, 0); + //glVertex3f(XRES*sdl_scale, (YRES+MENUSIZE)*sdl_scale, 1.0); + glVertex3f(XRES*sdl_scale, YRES*sdl_scale, 1.0); + glTexCoord2d(0, 0); + //glVertex3f(0, (YRES+MENUSIZE)*sdl_scale, 1.0); + glVertex3f(0, YRES*sdl_scale, 1.0); + glTexCoord2d(0, 1); + //glVertex3f(0, MENUSIZE*sdl_scale, 1.0); + glVertex3f(0, 0, 1.0); + glTexCoord2d(1, 1); + //glVertex3f(XRES*sdl_scale, MENUSIZE*sdl_scale, 1.0); + glVertex3f(XRES*sdl_scale, 0, 1.0); + glEnd(); + + if(display_mode & DISPLAY_WARP) + { + glUseProgram(0); + + } + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable( GL_TEXTURE_2D ); +#else + g->draw_image(vid, 0, 0, VIDXRES, VIDYRES, 255); +#endif +} + +void Renderer::RenderZoom() +{ + if(!zoomEnabled) + return; + #ifdef OGLR + int sdl_scale = 1; + int origBlendSrc, origBlendDst; + float zcx1, zcx0, zcy1, zcy0, yfactor, xfactor, i; //X-Factor is shit, btw + xfactor = 1.0f/(float)XRES; + yfactor = 1.0f/(float)YRES; + yfactor*=-1.0f; + + zcx1 = (zoomScopePosition.X)*xfactor; + zcx0 = (zoomScopePosition.X+zoomScopeSize)*xfactor; + zcy1 = (zoomScopePosition.Y-1)*yfactor; + zcy0 = ((zoomScopePosition.Y-1+zoomScopeSize))*yfactor; + + glGetIntegerv(GL_BLEND_SRC, &origBlendSrc); + glGetIntegerv(GL_BLEND_DST, &origBlendDst); + glBlendFunc(GL_ONE, GL_ZERO); + + glEnable( GL_TEXTURE_2D ); + //glReadBuffer(GL_AUX0); + glBindTexture(GL_TEXTURE_2D, partsFboTex); + + //Draw zoomed texture + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2d(zcx1, zcy1); + glVertex2i(zoomWindowPosition.X, zoomWindowPosition.Y); + glTexCoord2d(zcx0, zcy1); + glVertex2i(zoomWindowPosition.X+(zoomScopeSize*ZFACTOR), zoomWindowPosition.Y); + glTexCoord2d(zcx0, zcy0); + glVertex2i(zoomWindowPosition.X+(zoomScopeSize*ZFACTOR), zoomWindowPosition.Y+(zoomScopeSize*ZFACTOR)); + glTexCoord2d(zcx1, zcy0); + glVertex2i(zoomWindowPosition.X, zoomWindowPosition.Y+(zoomScopeSize*ZFACTOR)); + glEnd(); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable( GL_TEXTURE_2D ); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + //Lines to make the pixels stand out + glLineWidth(sdl_scale); + //glEnable(GL_LINE_SMOOTH); + glBegin(GL_LINES); + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + for(i = 0; i < zoomScopeSize; i++) + { + //Across + glVertex2i(zoomWindowPosition.X, zoomWindowPosition.Y+(i*ZFACTOR)); + glVertex2i(zoomWindowPosition.X+(zoomScopeSize*ZFACTOR), zoomWindowPosition.Y+(i*ZFACTOR)); + + //Down + glVertex2i(zoomWindowPosition.X+(i*ZFACTOR), zoomWindowPosition.Y); + glVertex2i(zoomWindowPosition.X+(i*ZFACTOR), zoomWindowPosition.Y+(zoomScopeSize*ZFACTOR)); + } + glEnd(); + + //Draw zoom window border + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glBegin(GL_LINE_LOOP); + glVertex2i(zoomWindowPosition.X, zoomWindowPosition.Y); + glVertex2i(zoomWindowPosition.X+(zoomScopeSize*ZFACTOR), zoomWindowPosition.Y); + glVertex2i(zoomWindowPosition.X+(zoomScopeSize*ZFACTOR), zoomWindowPosition.Y+(zoomScopeSize*ZFACTOR)); + glVertex2i(zoomWindowPosition.X, zoomWindowPosition.Y+(zoomScopeSize*ZFACTOR)); + glEnd(); + //glDisable(GL_LINE_SMOOTH); + + if(zoomEnabled) + { + glEnable(GL_COLOR_LOGIC_OP); + //glEnable(GL_LINE_SMOOTH); + glLogicOp(GL_XOR); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glBegin(GL_LINE_LOOP); + glVertex2i(zoomScopePosition.X, zoomScopePosition.Y); + glVertex2i(zoomScopePosition.X+zoomScopeSize, zoomScopePosition.Y); + glVertex2i(zoomScopePosition.X+zoomScopeSize, zoomScopePosition.Y+zoomScopeSize); + glVertex2i(zoomScopePosition.X, zoomScopePosition.Y+zoomScopeSize); + /*glVertex3i((zoomScopePosition.X-1)*sdl_scale, (YRES+MENUSIZE-(zoomScopePosition.Y-1))*sdl_scale, 0); + glVertex3i((zoomScopePosition.X-1)*sdl_scale, (YRES+MENUSIZE-(zoomScopePosition.Y+zoomScopeSize))*sdl_scale, 0); + glVertex3i((zoomScopePosition.X+zoomScopeSize)*sdl_scale, (YRES+MENUSIZE-(zoomScopePosition.Y+zoomScopeSize))*sdl_scale, 0); + glVertex3i((zoomScopePosition.X+zoomScopeSize)*sdl_scale, (YRES+MENUSIZE-(zoomScopePosition.Y-1))*sdl_scale, 0); + glVertex3i((zoomScopePosition.X-1)*sdl_scale, (YRES+MENUSIZE-(zoomScopePosition.Y-1))*sdl_scale, 0);*/ + glEnd(); + glDisable(GL_COLOR_LOGIC_OP); + } + glLineWidth(1); + glBlendFunc(origBlendSrc, origBlendDst); + #else + int x, y, i, j; + pixel pix; + pixel * img = vid; + drawrect(zoomWindowPosition.X-2, zoomWindowPosition.Y-2, zoomScopeSize*ZFACTOR+2, zoomScopeSize*ZFACTOR+2, 192, 192, 192, 255); + drawrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR, zoomScopeSize*ZFACTOR, 0, 0, 0, 255); + clearrect(zoomWindowPosition.X, zoomWindowPosition.Y, zoomScopeSize*ZFACTOR, zoomScopeSize*ZFACTOR); + for (j=0; jbmap; + unsigned char (*emap)[XRES/CELL] = sim->emap; + wall_type *wtypes = sim->wtypes; + for (y=0; y=UI_WALLCOUNT) + continue; + pc = wtypes[wt].colour; + gc = wtypes[wt].eglow; + + // standard wall patterns + if (wtypes[wt].drawstyle==1) + { + for (j=0; j>1)&1; i 255) cr = 255; + fire_r[y][x] = cr; + cg = fire_g[y][x] + PIXG(pc); + if (cg > 255) cg = 255; + fire_g[y][x] = cg; + cb = fire_b[y][x] + PIXB(pc); + if (cb > 255) cb = 255; + fire_b[y][x] = cb; + + } + } +#endif +} + +void Renderer::DrawSigns() +{ + int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq; + std::vector signs = sim->signs; +#ifdef OGLR + GLint prevFbo; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); + glTranslated(0, MENUSIZE, 0); +#endif + for (i=0; i < signs.size(); i++) + if (signs[i].text.length()) + { + char buff[256]; //Buffer + sim->signs[i].pos(x, y, w, h); + clearrect(x, y, w, h); + drawrect(x, y, w, h, 192, 192, 192, 255); + + //Displaying special information + if (signs[i].text == "{p}") + { + float pressure = 0.0f; + if (signs[i].x>=0 && signs[i].x=0 && signs[i].ypv[signs[i].y/CELL][signs[i].x/CELL]; + sprintf(buff, "Pressure: %3.2f", pressure); //...pressure + drawtext(x+3, y+3, buff, 255, 255, 255, 255); + } + else if (signs[i].text == "{t}") + { + if (signs[i].x>=0 && signs[i].x=0 && signs[i].ypmap[signs[i].y][signs[i].x]) + sprintf(buff, "Temp: %4.2f", sim->parts[sim->pmap[signs[i].y][signs[i].x]>>8].temp-273.15); //...temperature + else + sprintf(buff, "Temp: 0.00"); //...temperature + drawtext(x+3, y+3, buff, 255, 255, 255, 255); + } + else if (sregexp(signs[i].text.c_str(), "^{c:[0-9]*|.*}$")==0) + { + int sldr, startm; + memset(buff, 0, sizeof(buff)); + for (sldr=3; signs[i].text[sldr-1] != '|'; sldr++) + startm = sldr + 1; + sldr = startm; + while (signs[i].text[sldr] != '}') + { + buff[sldr - startm] = signs[i].text[sldr]; + sldr++; + } + drawtext(x+3, y+3, buff, 0, 191, 255, 255); + } + else + { + drawtext(x+3, y+3, signs[i].text, 255, 255, 255, 255); + } + + x = signs[i].x; + y = signs[i].y; + dx = 1 - signs[i].ju; + dy = (signs[i].y > 18) ? -1 : 1; +#ifdef OGLR + glBegin(GL_LINES); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glVertex2i(x, y); + glVertex2i(x+(dx*4), y+(dy*4)); + glEnd(); +#else + for (j=0; j<4; j++) + { + blendpixel(x, y, 192, 192, 192, 255); + x+=dx; + y+=dy; + } +#endif + /*if (MSIGN==i) + { + bq = b; + b = SDL_GetMouseState(&mx, &my); + mx /= sdl_scale; + my /= sdl_scale; + signs[i].x = mx; + signs[i].y = my; + }*/ + } +#ifdef OGLR + glTranslated(0, -MENUSIZE, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); +#endif +} + +void Renderer::render_gravlensing() +{ +#ifndef OGLR + int nx, ny, rx, ry, gx, gy, bx, by, co; + int r, g, b; + pixel t; + pixel *src = vid; + pixel *dst = vid; + for(nx = 0; nx < XRES; nx++) + { + for(ny = 0; ny < YRES; ny++) + { + co = (ny/CELL)*(XRES/CELL)+(nx/CELL); + rx = (int)(nx-sim->gravx[co]*0.75f+0.5f); + ry = (int)(ny-sim->gravy[co]*0.75f+0.5f); + gx = (int)(nx-sim->gravx[co]*0.875f+0.5f); + gy = (int)(ny-sim->gravy[co]*0.875f+0.5f); + bx = (int)(nx-sim->gravx[co]+0.5f); + by = (int)(ny-sim->gravy[co]+0.5f); + if(rx > 0 && rx < XRES && ry > 0 && ry < YRES && gx > 0 && gx < XRES && gy > 0 && gy < YRES && bx > 0 && bx < XRES && by > 0 && by < YRES) + { + t = dst[ny*(VIDXRES)+nx]; + r = PIXR(src[ry*(VIDXRES)+rx]) + PIXR(t); + g = PIXG(src[gy*(VIDXRES)+gx]) + PIXG(t); + b = PIXB(src[by*(VIDXRES)+bx]) + PIXB(t); + if (r>255) + r = 255; + if (g>255) + g = 255; + if (b>255) + b = 255; + dst[ny*(VIDXRES)+nx] = PIXRGB(r,g,b); + } + } + } +#endif +} + +void Renderer::render_fire() +{ +#ifndef OGLR + int i,j,x,y,r,g,b,nx,ny; + for (j=0; j=0 && j+y>=0 && i+x4 ? r-4 : 0; + fire_g[j][i] = g>4 ? g-4 : 0; + fire_b[j][i] = b>4 ? b-4 : 0; + } +#endif +} + +float temp[CELL*3][CELL*3]; +float fire_alphaf[CELL*3][CELL*3]; +float glow_alphaf[11][11]; +float blur_alphaf[7][7]; +void Renderer::prepare_alpha(int size, float intensity) +{ + //TODO: implement size + int x,y,i,j,c; + float multiplier = 255.0f*intensity; + + memset(temp, 0, sizeof(temp)); + for (x=0; x 7) + continue; + glow_alphaf[c+x][c-y] += 0.02f; + glow_alphaf[c-x][c+y] += 0.02f; + glow_alphaf[c+x][c+y] += 0.02f; + glow_alphaf[c-x][c-y] += 0.02f; + } + } + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, glowAlpha); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 11, 11, GL_ALPHA, GL_FLOAT, glow_alphaf); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + c = 3; + + for (x=-3; x<4; x++) + { + for (y=-3; y<4; y++) + { + if (abs(x)+abs(y) <2 && !(abs(x)==2||abs(y)==2)) + blur_alphaf[c+x][c-y] = 0.11f; + if (abs(x)+abs(y) <=3 && abs(x)+abs(y)) + blur_alphaf[c+x][c-y] = 0.08f; + if (abs(x)+abs(y) == 2) + blur_alphaf[c+x][c-y] = 0.04f; + } + } + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, blurAlpha); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 7, 7, GL_ALPHA, GL_FLOAT, blur_alphaf); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); +#endif +} + +void Renderer::render_parts() +{ + int deca, decr, decg, decb, cola, colr, colg, colb, firea, firer, fireg, fireb, pixel_mode, q, i, t, nx, ny, x, y, caddress; + int orbd[4] = {0, 0, 0, 0}, orbl[4] = {0, 0, 0, 0}; + float gradv, flicker, fnx, fny; + Particle * parts; + part_transition *ptransitions; + Element *elements; + if(!sim) + return; + parts = sim->parts; + elements = sim->elements; +#ifdef OGLR + int cfireV = 0, cfireC = 0, cfire = 0; + int csmokeV = 0, csmokeC = 0, csmoke = 0; + int cblobV = 0, cblobC = 0, cblob = 0; + int cblurV = 0, cblurC = 0, cblur = 0; + int cglowV = 0, cglowC = 0, cglow = 0; + int cflatV = 0, cflatC = 0, cflat = 0; + int caddV = 0, caddC = 0, cadd = 0; + int clineV = 0, clineC = 0, cline = 0; + GLint origBlendSrc, origBlendDst, prevFbo; + + glGetIntegerv(GL_BLEND_SRC, &origBlendSrc); + glGetIntegerv(GL_BLEND_DST, &origBlendDst); + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); + //Render to the particle FBO + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); + glTranslated(0, MENUSIZE, 0); +#else + /*if (GRID_MODE)//draws the grid + { + for (ny=0; nyparts_lastActiveIndex; i++) { + if (sim->parts[i].type) { + t = sim->parts[i].type; + + nx = (int)(sim->parts[i].x+0.5f); + ny = (int)(sim->parts[i].y+0.5f); + fnx = sim->parts[i].x; + fny = sim->parts[i].y; + + if((sim->photons[ny][nx]&0xFF) && !(sim->elements[t].Properties & TYPE_ENERGY) && t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH) + continue; + if(nx >= XRES || nx < 0 || ny >= YRES || ny < 0) + continue; + + //Defaults + pixel_mode = 0 | PMODE_FLAT; + cola = 255; + colr = PIXR(elements[t].Colour); + colg = PIXG(elements[t].Colour); + colb = PIXB(elements[t].Colour); + firea = 0; + + deca = (sim->parts[i].dcolour>>24)&0xFF; + decr = (sim->parts[i].dcolour>>16)&0xFF; + decg = (sim->parts[i].dcolour>>8)&0xFF; + decb = (sim->parts[i].dcolour)&0xFF; + + { + if (graphicscache[t].isready) + { + pixel_mode = graphicscache[t].pixel_mode; + cola = graphicscache[t].cola; + colr = graphicscache[t].colr; + colg = graphicscache[t].colg; + colb = graphicscache[t].colb; + firea = graphicscache[t].firea; + firer = graphicscache[t].firer; + fireg = graphicscache[t].fireg; + fireb = graphicscache[t].fireb; + } + else if(!(colour_mode & COLOUR_BASC)) + { + if (elements[t].Graphics) + { + if ((*(elements[t].Graphics))(this, &(sim->parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb)) //That's a lot of args, a struct might be better + { + graphicscache[t].isready = 1; + graphicscache[t].pixel_mode = pixel_mode; + graphicscache[t].cola = cola; + graphicscache[t].colr = colr; + graphicscache[t].colg = colg; + graphicscache[t].colb = colb; + graphicscache[t].firea = firea; + graphicscache[t].firer = firer; + graphicscache[t].fireg = fireg; + graphicscache[t].fireb = fireb; + } + } + else + { + graphicscache[t].isready = 1; + graphicscache[t].pixel_mode = pixel_mode; + graphicscache[t].cola = cola; + graphicscache[t].colr = colr; + graphicscache[t].colg = colg; + graphicscache[t].colb = colb; + graphicscache[t].firea = firea; + graphicscache[t].firer = firer; + graphicscache[t].fireg = fireg; + graphicscache[t].fireb = fireb; + } + } + if((elements[t].Properties & PROP_HOT_GLOW) && sim->parts[i].temp>(elements[t].HighTemperature-800.0f)) + { + gradv = 3.1415/(2*elements[t].HighTemperature-(elements[t].HighTemperature-800.0f)); + caddress = (sim->parts[i].temp>elements[t].HighTemperature)?elements[t].HighTemperature-(elements[t].HighTemperature-800.0f):sim->parts[i].temp-(elements[t].HighTemperature-800.0f); + colr += sin(gradv*caddress) * 226;; + colg += sin(gradv*caddress*4.55 +3.14) * 34; + colb += sin(gradv*caddress*2.22 +3.14) * 64; + } + + if((pixel_mode & FIRE_ADD) && !(render_mode & FIRE_ADD)) + pixel_mode |= PMODE_GLOW; + if((pixel_mode & FIRE_BLEND) && !(render_mode & FIRE_BLEND)) + pixel_mode |= PMODE_BLUR; + if((pixel_mode & PMODE_BLUR) && !(render_mode & PMODE_BLUR)) + pixel_mode |= PMODE_FLAT; + if((pixel_mode & PMODE_GLOW) && !(render_mode & PMODE_GLOW)) + pixel_mode |= PMODE_BLEND; + if (render_mode & PMODE_BLOB) + pixel_mode |= PMODE_BLOB; + + pixel_mode &= render_mode; + + //Alter colour based on display mode + if(colour_mode & COLOUR_HEAT) + { + caddress = restrict_flt((int)( restrict_flt((float)(sim->parts[i].temp+(-MIN_TEMP)), 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); + firea = 255; + firer = colr = (unsigned char)color_data[caddress]; + fireg = colg = (unsigned char)color_data[caddress+1]; + fireb = colb = (unsigned char)color_data[caddress+2]; + cola = 255; + if(pixel_mode & (FIREMODE | PMODE_GLOW)) pixel_mode = (pixel_mode & ~(FIREMODE|PMODE_GLOW)) | PMODE_BLUR; + } + else if(colour_mode & COLOUR_LIFE) + { + gradv = 0.4f; + if (!(sim->parts[i].life<5)) + q = sqrt(sim->parts[i].life); + else + q = sim->parts[i].life; + colr = colg = colb = sin(gradv*q) * 100 + 128; + cola = 255; + if(pixel_mode & (FIREMODE | PMODE_GLOW)) pixel_mode = (pixel_mode & ~(FIREMODE|PMODE_GLOW)) | PMODE_BLUR; + } + else if(colour_mode & COLOUR_BASC) + { + colr = PIXR(elements[t].Colour); + colg = PIXG(elements[t].Colour); + colb = PIXB(elements[t].Colour); + pixel_mode = PMODE_FLAT; + } + + //Apply decoration colour + if(!(colour_mode & ~COLOUR_GRAD)) + { + if(!(pixel_mode & NO_DECO) && decorations_enable) + { + colr = (deca*decr + (255-deca)*colr) >> 8; + colg = (deca*decg + (255-deca)*colg) >> 8; + colb = (deca*decb + (255-deca)*colb) >> 8; + } + + if((pixel_mode & DECO_FIRE) && decorations_enable) + { + firer = (deca*decr + (255-deca)*firer) >> 8; + fireg = (deca*decg + (255-deca)*fireg) >> 8; + fireb = (deca*decb + (255-deca)*fireb) >> 8; + } + } + + if (colour_mode & COLOUR_GRAD) + { + float frequency = 0.05; + int q = sim->parts[i].temp-40; + colr = sin(frequency*q) * 16 + colr; + colg = sin(frequency*q) * 16 + colg; + colb = sin(frequency*q) * 16 + colb; + if(pixel_mode & (FIREMODE | PMODE_GLOW)) pixel_mode = (pixel_mode & ~(FIREMODE|PMODE_GLOW)) | PMODE_BLUR; + } + + #ifndef OGLR + //All colours are now set, check ranges + if(colr>255) colr = 255; + else if(colr<0) colr = 0; + if(colg>255) colg = 255; + else if(colg<0) colg = 0; + if(colb>255) colb = 255; + else if(colb<0) colb = 0; + if(cola>255) cola = 255; + else if(cola<0) cola = 0; + + if(firer>255) firer = 255; + else if(firer<0) firer = 0; + if(fireg>255) fireg = 255; + else if(fireg<0) fireg = 0; + if(fireb>255) fireb = 255; + else if(fireb<0) fireb = 0; + if(firea>255) firea = 255; + else if(firea<0) firea = 0; + #endif + + //Pixel rendering + if(pixel_mode & PSPEC_STICKMAN) + { + char buff[20]; //Buffer for HP + int s; + int legr, legg, legb; + playerst *cplayer; + if(t==PT_STKM) + cplayer = &sim->player; + else if(t==PT_STKM2) + cplayer = &sim->player2; + else if(t==PT_FIGH) + cplayer = &sim->fighters[(unsigned char)sim->parts[i].tmp]; + else + continue; + +/* if (mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head + { + sprintf(buff, "%3d", sim->parts[i].life); //Show HP + drawtext(mousex-8-2*(sim->parts[i].life<100)-2*(sim->parts[i].life<10), mousey-12, buff, 255, 255, 255, 255); + }*/ + + if (colour_mode!=COLOUR_HEAT) + { + if (cplayer->elemelem].Colour); + colg = PIXG(elements[cplayer->elem].Colour); + colb = PIXB(elements[cplayer->elem].Colour); + } + else + { + colr = 0x80; + colg = 0x80; + colb = 0xFF; + } + } +#ifdef OGLR + glColor4f(((float)colr)/255.0f, ((float)colg)/255.0f, ((float)colb)/255.0f, 1.0f); + glBegin(GL_LINE_STRIP); + if(t==PT_FIGH) + { + glVertex2f(fnx, fny+2); + glVertex2f(fnx+2, fny); + glVertex2f(fnx, fny-2); + glVertex2f(fnx-2, fny); + glVertex2f(fnx, fny+2); + } + else + { + glVertex2f(fnx-2, fny-2); + glVertex2f(fnx+2, fny-2); + glVertex2f(fnx+2, fny+2); + glVertex2f(fnx-2, fny+2); + glVertex2f(fnx-2, fny-2); + } + glEnd(); + glBegin(GL_LINES); + + if (colour_mode!=COLOUR_HEAT) + { + if (t==PT_STKM2) + glColor4f(100.0f/255.0f, 100.0f/255.0f, 1.0f, 1.0f); + else + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } + + glVertex2f(nx, ny+3); + glVertex2f(cplayer->legs[0], cplayer->legs[1]); + + glVertex2f(cplayer->legs[0], cplayer->legs[1]); + glVertex2f(cplayer->legs[4], cplayer->legs[5]); + + glVertex2f(nx, ny+3); + glVertex2f(cplayer->legs[8], cplayer->legs[9]); + + glVertex2f(cplayer->legs[8], cplayer->legs[9]); + glVertex2f(cplayer->legs[12], cplayer->legs[13]); + glEnd(); +#else + s = VIDXRES; + + if (t==PT_STKM2) + { + legr = 100; + legg = 100; + legb = 255; + } + else + { + legr = 255; + legg = 255; + legb = 255; + } + + if (colour_mode==COLOUR_HEAT) + { + legr = colr; + legg = colg; + legb = colb; + } + + //head + if(t==PT_FIGH) + { + draw_line(nx, ny+2, nx+2, ny, colr, colg, colb, s); + draw_line(nx+2, ny, nx, ny-2, colr, colg, colb, s); + draw_line(nx, ny-2, nx-2, ny, colr, colg, colb, s); + draw_line(nx-2, ny, nx, ny+2, colr, colg, colb, s); + } + else + { + draw_line(nx-2, ny+2, nx+2, ny+2, colr, colg, colb, s); + draw_line(nx-2, ny-2, nx+2, ny-2, colr, colg, colb, s); + draw_line(nx-2, ny-2, nx-2, ny+2, colr, colg, colb, s); + draw_line(nx+2, ny-2, nx+2, ny+2, colr, colg, colb, s); + } + //legs + draw_line(nx, ny+3, cplayer->legs[0], cplayer->legs[1], legr, legg, legb, s); + draw_line(cplayer->legs[0], cplayer->legs[1], cplayer->legs[4], cplayer->legs[5], legr, legg, legb, s); + draw_line(nx, ny+3, cplayer->legs[8], cplayer->legs[9], legr, legg, legb, s); + draw_line(cplayer->legs[8], cplayer->legs[9], cplayer->legs[12], cplayer->legs[13], legr, legg, legb, s); +#endif + } + if(pixel_mode & PMODE_FLAT) + { +#ifdef OGLR + flatV[cflatV++] = nx; + flatV[cflatV++] = ny; + flatC[cflatC++] = ((float)colr)/255.0f; + flatC[cflatC++] = ((float)colg)/255.0f; + flatC[cflatC++] = ((float)colb)/255.0f; + flatC[cflatC++] = 1.0f; + cflat++; +#else + vid[ny*(VIDXRES)+nx] = PIXRGB(colr,colg,colb); +#endif + } + if(pixel_mode & PMODE_BLEND) + { +#ifdef OGLR + flatV[cflatV++] = nx; + flatV[cflatV++] = ny; + flatC[cflatC++] = ((float)colr)/255.0f; + flatC[cflatC++] = ((float)colg)/255.0f; + flatC[cflatC++] = ((float)colb)/255.0f; + flatC[cflatC++] = ((float)cola)/255.0f; + cflat++; +#else + blendpixel(nx, ny, colr, colg, colb, cola); +#endif + } + if(pixel_mode & PMODE_ADD) + { +#ifdef OGLR + addV[caddV++] = nx; + addV[caddV++] = ny; + addC[caddC++] = ((float)colr)/255.0f; + addC[caddC++] = ((float)colg)/255.0f; + addC[caddC++] = ((float)colb)/255.0f; + addC[caddC++] = ((float)cola)/255.0f; + cadd++; +#else + addpixel(nx, ny, colr, colg, colb, cola); +#endif + } + if(pixel_mode & PMODE_BLOB) + { +#ifdef OGLR + blobV[cblobV++] = nx; + blobV[cblobV++] = ny; + blobC[cblobC++] = ((float)colr)/255.0f; + blobC[cblobC++] = ((float)colg)/255.0f; + blobC[cblobC++] = ((float)colb)/255.0f; + blobC[cblobC++] = 1.0f; + cblob++; +#else + vid[ny*(VIDXRES)+nx] = PIXRGB(colr,colg,colb); + + blendpixel(nx+1, ny, colr, colg, colb, 223); + blendpixel(nx-1, ny, colr, colg, colb, 223); + blendpixel(nx, ny+1, colr, colg, colb, 223); + blendpixel(nx, ny-1, colr, colg, colb, 223); + + blendpixel(nx+1, ny-1, colr, colg, colb, 112); + blendpixel(nx-1, ny-1, colr, colg, colb, 112); + blendpixel(nx+1, ny+1, colr, colg, colb, 112); + blendpixel(nx-1, ny+1, colr, colg, colb, 112); +#endif + } + if(pixel_mode & PMODE_GLOW) + { + int cola1 = (5*cola)/255; +#ifdef OGLR + glowV[cglowV++] = nx; + glowV[cglowV++] = ny; + glowC[cglowC++] = ((float)colr)/255.0f; + glowC[cglowC++] = ((float)colg)/255.0f; + glowC[cglowC++] = ((float)colb)/255.0f; + glowC[cglowC++] = 1.0f; + cglow++; +#else + addpixel(nx, ny, colr, colg, colb, (192*cola)/255); + addpixel(nx+1, ny, colr, colg, colb, (96*cola)/255); + addpixel(nx-1, ny, colr, colg, colb, (96*cola)/255); + addpixel(nx, ny+1, colr, colg, colb, (96*cola)/255); + addpixel(nx, ny-1, colr, colg, colb, (96*cola)/255); + + for (x = 1; x < 6; x++) { + addpixel(nx, ny-x, colr, colg, colb, cola1); + addpixel(nx, ny+x, colr, colg, colb, cola1); + addpixel(nx-x, ny, colr, colg, colb, cola1); + addpixel(nx+x, ny, colr, colg, colb, cola1); + for (y = 1; y < 6; y++) { + if(x + y > 7) + continue; + addpixel(nx+x, ny-y, colr, colg, colb, cola1); + addpixel(nx-x, ny+y, colr, colg, colb, cola1); + addpixel(nx+x, ny+y, colr, colg, colb, cola1); + addpixel(nx-x, ny-y, colr, colg, colb, cola1); + } + } +#endif + } + if(pixel_mode & PMODE_BLUR) + { +#ifdef OGLR + blurV[cblurV++] = nx; + blurV[cblurV++] = ny; + blurC[cblurC++] = ((float)colr)/255.0f; + blurC[cblurC++] = ((float)colg)/255.0f; + blurC[cblurC++] = ((float)colb)/255.0f; + blurC[cblurC++] = 1.0f; + cblur++; +#else + for (x=-3; x<4; x++) + { + for (y=-3; y<4; y++) + { + if (abs(x)+abs(y) <2 && !(abs(x)==2||abs(y)==2)) + blendpixel(x+nx, y+ny, colr, colg, colb, 30); + if (abs(x)+abs(y) <=3 && abs(x)+abs(y)) + blendpixel(x+nx, y+ny, colr, colg, colb, 20); + if (abs(x)+abs(y) == 2) + blendpixel(x+nx, y+ny, colr, colg, colb, 10); + } + } +#endif + } + if(pixel_mode & PMODE_SPARK) + { + flicker = rand()%20; +#ifdef OGLR + //Oh god, this is awful + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx-5; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 1.0f - ((float)flicker)/30; + lineV[clineV++] = fnx; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx+5; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx; + lineV[clineV++] = fny-5; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 1.0f - ((float)flicker)/30; + lineV[clineV++] = fnx; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx; + lineV[clineV++] = fny+5; + cline++; +#else + gradv = 4*sim->parts[i].life + flicker; + for (x = 0; gradv>0.5; x++) { + addpixel(nx+x, ny, colr, colg, colb, gradv); + addpixel(nx-x, ny, colr, colg, colb, gradv); + + addpixel(nx, ny+x, colr, colg, colb, gradv); + addpixel(nx, ny-x, colr, colg, colb, gradv); + gradv = gradv/1.5f; + } +#endif + } + if(pixel_mode & PMODE_FLARE) + { + flicker = rand()%20; +#ifdef OGLR + //Oh god, this is awful + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx-10; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 1.0f - ((float)flicker)/40; + lineV[clineV++] = fnx; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx+10; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx; + lineV[clineV++] = fny-10; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 1.0f - ((float)flicker)/30; + lineV[clineV++] = fnx; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx; + lineV[clineV++] = fny+10; + cline++; +#else + gradv = flicker + fabs(parts[i].vx)*17 + fabs(sim->parts[i].vy)*17; + blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); + blendpixel(nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + if (gradv>255) gradv=255; + blendpixel(nx+1, ny-1, colr, colg, colb, gradv); + blendpixel(nx-1, ny-1, colr, colg, colb, gradv); + blendpixel(nx+1, ny+1, colr, colg, colb, gradv); + blendpixel(nx-1, ny+1, colr, colg, colb, gradv); + for (x = 1; gradv>0.5; x++) { + addpixel(nx+x, ny, colr, colg, colb, gradv); + addpixel(nx-x, ny, colr, colg, colb, gradv); + addpixel(nx, ny+x, colr, colg, colb, gradv); + addpixel(nx, ny-x, colr, colg, colb, gradv); + gradv = gradv/1.2f; + } +#endif + } + if(pixel_mode & PMODE_LFLARE) + { + flicker = rand()%20; +#ifdef OGLR + //Oh god, this is awful + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx-70; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 1.0f - ((float)flicker)/30; + lineV[clineV++] = fnx; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx+70; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx; + lineV[clineV++] = fny-70; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 1.0f - ((float)flicker)/50; + lineV[clineV++] = fnx; + lineV[clineV++] = fny; + cline++; + + lineC[clineC++] = ((float)colr)/255.0f; + lineC[clineC++] = ((float)colg)/255.0f; + lineC[clineC++] = ((float)colb)/255.0f; + lineC[clineC++] = 0.0f; + lineV[clineV++] = fnx; + lineV[clineV++] = fny+70; + cline++; +#else + gradv = flicker + fabs(parts[i].vx)*17 + fabs(parts[i].vy)*17; + blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); + blendpixel(nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + if (gradv>255) gradv=255; + blendpixel(nx+1, ny-1, colr, colg, colb, gradv); + blendpixel(nx-1, ny-1, colr, colg, colb, gradv); + blendpixel(nx+1, ny+1, colr, colg, colb, gradv); + blendpixel(nx-1, ny+1, colr, colg, colb, gradv); + for (x = 1; gradv>0.5; x++) { + addpixel(nx+x, ny, colr, colg, colb, gradv); + addpixel(nx-x, ny, colr, colg, colb, gradv); + addpixel(nx, ny+x, colr, colg, colb, gradv); + addpixel(nx, ny-x, colr, colg, colb, gradv); + gradv = gradv/1.01f; + } +#endif + } + if (pixel_mode & EFFECT_GRAVIN) + { + int nxo = 0; + int nyo = 0; + int r; + int fire_rv = 0; + float drad = 0.0f; + float ddist = 0.0f; + sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); + for (r = 0; r < 4; r++) { + ddist = ((float)orbd[r])/16.0f; + drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; + nxo = ddist*cos(drad); + nyo = ddist*sin(drad); + if (ny+nyo>0 && ny+nyo0 && nx+nxoorbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); + for (r = 0; r < 4; r++) { + ddist = ((float)orbd[r])/16.0f; + drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; + nxo = ddist*cos(drad); + nyo = ddist*sin(drad); + if (ny+nyo>0 && ny+nyo0 && nx+nxo> 8; + fire_g[ny/CELL][nx/CELL] = (firea*fireg + (255-firea)*fire_g[ny/CELL][nx/CELL]) >> 8; + fire_b[ny/CELL][nx/CELL] = (firea*fireb + (255-firea)*fire_b[ny/CELL][nx/CELL]) >> 8; +#endif + } + if(firea && (pixel_mode & FIRE_ADD)) + { +#ifdef OGLR + fireV[cfireV++] = nx; + fireV[cfireV++] = ny; + fireC[cfireC++] = ((float)firer)/255.0f; + fireC[cfireC++] = ((float)fireg)/255.0f; + fireC[cfireC++] = ((float)fireb)/255.0f; + fireC[cfireC++] = ((float)firea)/255.0f; + cfire++; +#else + firea /= 8; + firer = ((firea*firer) >> 8) + fire_r[ny/CELL][nx/CELL]; + fireg = ((firea*fireg) >> 8) + fire_g[ny/CELL][nx/CELL]; + fireb = ((firea*fireb) >> 8) + fire_b[ny/CELL][nx/CELL]; + + if(firer>255) + firer = 255; + if(fireg>255) + fireg = 255; + if(fireb>255) + fireb = 255; + + fire_r[ny/CELL][nx/CELL] = firer; + fire_g[ny/CELL][nx/CELL] = fireg; + fire_b[ny/CELL][nx/CELL] = fireb; +#endif + } + } + } + } +#ifdef OGLR + + //Go into array mode + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + if(cflat) + { + // -- BEGIN FLAT -- // + //Set point size (size of fire texture) + glPointSize(1.0f); + + glColorPointer(4, GL_FLOAT, 0, &flatC[0]); + glVertexPointer(2, GL_INT, 0, &flatV[0]); + + glDrawArrays(GL_POINTS, 0, cflat); + + //Clear some stuff we set + // -- END FLAT -- // + } + + if(cblob) + { + // -- BEGIN BLOB -- // + glEnable( GL_POINT_SMOOTH ); //Blobs! + glPointSize(2.5f); + + glColorPointer(4, GL_FLOAT, 0, &blobC[0]); + glVertexPointer(2, GL_INT, 0, &blobV[0]); + + glDrawArrays(GL_POINTS, 0, cblob); + + //Clear some stuff we set + glDisable( GL_POINT_SMOOTH ); + // -- END BLOB -- // + } + + if(cglow || cblur) + { + // -- BEGIN GLOW -- // + //Start and prepare fire program + glEnable(GL_TEXTURE_2D); + glUseProgram(fireProg); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, glowAlpha); + glUniform1i(glGetUniformLocation(fireProg, "fireAlpha"), 0); + + glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); + + //Make sure we can use texture coords on points + glEnable(GL_POINT_SPRITE); + glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); + glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); + + //Set point size (size of fire texture) + glPointSize(11.0f); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + if(cglow) + { + glColorPointer(4, GL_FLOAT, 0, &glowC[0]); + glVertexPointer(2, GL_INT, 0, &glowV[0]); + + glDrawArrays(GL_POINTS, 0, cglow); + } + + glPointSize(7.0f); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + if(cblur) + { + glBindTexture(GL_TEXTURE_2D, blurAlpha); + + glColorPointer(4, GL_FLOAT, 0, &blurC[0]); + glVertexPointer(2, GL_INT, 0, &blurV[0]); + + glDrawArrays(GL_POINTS, 0, cblur); + } + + //Clear some stuff we set + glDisable(GL_POINT_SPRITE); + glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); + glUseProgram(0); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + // -- END GLOW -- // + } + + if(cadd) + { + // -- BEGIN ADD -- // + //Set point size (size of fire texture) + glPointSize(1.0f); + + glColorPointer(4, GL_FLOAT, 0, &addC[0]); + glVertexPointer(2, GL_INT, 0, &addV[0]); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glDrawArrays(GL_POINTS, 0, cadd); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + //Clear some stuff we set + // -- END ADD -- // + } + + if(cline) + { + // -- BEGIN LINES -- // + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glEnable( GL_LINE_SMOOTH ); + glColorPointer(4, GL_FLOAT, 0, &lineC[0]); + glVertexPointer(2, GL_FLOAT, 0, &lineV[0]); + + glDrawArrays(GL_LINE_STRIP, 0, cline); + + //Clear some stuff we set + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_LINE_SMOOTH); + // -- END LINES -- // + } + + if(cfire || csmoke) + { + // -- BEGIN FIRE -- // + //Start and prepare fire program + glEnable(GL_TEXTURE_2D); + glUseProgram(fireProg); + //glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, fireAlpha); + glUniform1i(glGetUniformLocation(fireProg, "fireAlpha"), 0); + + //Make sure we can use texture coords on points + glEnable(GL_POINT_SPRITE); + glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); + glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); + + //Set point size (size of fire texture) + glPointSize(CELL*3); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + if(cfire) + { + glColorPointer(4, GL_FLOAT, 0, &fireC[0]); + glVertexPointer(2, GL_INT, 0, &fireV[0]); + + glDrawArrays(GL_POINTS, 0, cfire); + } + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + if(csmoke) + { + glColorPointer(4, GL_FLOAT, 0, &smokeC[0]); + glVertexPointer(2, GL_INT, 0, &smokeV[0]); + + glDrawArrays(GL_POINTS, 0, csmoke); + } + + //Clear some stuff we set + glDisable(GL_POINT_SPRITE); + glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); + glUseProgram(0); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + // -- END FIRE -- // + } + + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + + //Reset FBO + glTranslated(0, -MENUSIZE, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); + + glBlendFunc(origBlendSrc, origBlendDst); +#endif +} + +void Renderer::draw_other() // EMP effect +{ + int i, j; + //if (emp_decor>0 && !sys_pause) emp_decor-=emp_decor/25+2; TODO: Render should render only, do not change simulation state + if (emp_decor>40) emp_decor=40; + if (emp_decor<0) emp_decor = 0; + if (!(display_mode & DISPLAY_EFFE)) // no in nothing mode + return; + if (emp_decor>0) + { +#ifdef OGLR + GLint prevFbo; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); + glTranslated(0, MENUSIZE, 0); + float femp_decor = ((float)emp_decor)/255.0f; + /*int r=emp_decor*2.5, g=100+emp_decor*1.5, b=255; + int a=(1.0*emp_decor/110)*255; + if (r>255) r=255; + if (g>255) g=255; + if (b>255) g=255; + if (a>255) a=255;*/ + glBegin(GL_QUADS); + glColor4f(femp_decor*2.5f, 0.4f+femp_decor*1.5f, 1.0f+femp_decor*1.5f, femp_decor/0.44f); + glVertex2f(0, MENUSIZE); + glVertex2f(XRES, MENUSIZE); + glVertex2f(XRES, YRES+MENUSIZE); + glVertex2f(0, YRES+MENUSIZE); + glEnd(); + glTranslated(0, -MENUSIZE, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); +#else + int r=emp_decor*2.5, g=100+emp_decor*1.5, b=255; + int a=(1.0*emp_decor/110)*255; + if (r>255) r=255; + if (g>255) g=255; + if (b>255) g=255; + if (a>255) a=255; + for (j=0; jgravx[ca]) <= 0.001f && fabsf(sim->gravy[ca]) <= 0.001f) + continue; + nx = x*CELL; + ny = y*CELL; + dist = fabsf(sim->gravy[ca])+fabsf(sim->gravx[ca]); + for(i = 0; i < 4; i++) + { + nx -= sim->gravx[ca]*0.5f; + ny -= sim->gravy[ca]*0.5f; + addpixel((int)(nx+0.5f), (int)(ny+0.5f), 255, 255, 255, (int)(dist*20.0f)); + } + } + } +} + +void Renderer::draw_air() +{ +#ifndef OGLR + if(!(display_mode & DISPLAY_AIR)) + return; + int x, y, i, j; + float (*pv)[XRES/CELL] = sim->air->pv; + float (*hv)[XRES/CELL] = sim->air->hv; + float (*vx)[XRES/CELL] = sim->air->vx; + float (*vy)[XRES/CELL] = sim->air->vy; + pixel c; + for (y=0; y 0.0f) + c = PIXRGB(clamp_flt(pv[y][x], 0.0f, 8.0f), 0, 0);//positive pressure is red! + else + c = PIXRGB(0, 0, clamp_flt(-pv[y][x], 0.0f, 8.0f));//negative pressure is blue! + } + else if (display_mode & DISPLAY_AIRV) + { + c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red + clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green + clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue + } + else if (display_mode & DISPLAY_AIRH) + { + float ttemp = hv[y][x]+(-MIN_TEMP); + int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); + c = PIXRGB((int)((unsigned char)color_data[caddress]*0.7f), (int)((unsigned char)color_data[caddress+1]*0.7f), (int)((unsigned char)color_data[caddress+2]*0.7f)); + //c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red + // clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green + // clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue + } + else if (display_mode & DISPLAY_AIRC) + { + int r; + int g; + int b; + // velocity adds grey + r = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); + g = clamp_flt(fabsf(vx[y][x]), 0.0f, 20.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 24.0f); + b = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); + if (pv[y][x] > 0.0f) + { + r += clamp_flt(pv[y][x], 0.0f, 16.0f);//pressure adds red! + if (r>255) + r=255; + if (g>255) + g=255; + if (b>255) + b=255; + c = PIXRGB(r, g, b); + } + else + { + b += clamp_flt(-pv[y][x], 0.0f, 16.0f);//pressure adds blue! + if (r>255) + r=255; + if (g>255) + g=255; + if (b>255) + b=255; + c = PIXRGB(r, g, b); + } + } + for (j=0; jair->vx); + glUniform1i(glGetUniformLocation(airProg, "airX"), 0); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, airVY); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_GREEN, GL_FLOAT, sim->air->vy); + glUniform1i(glGetUniformLocation(airProg, "airY"), 1); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, airPV); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_BLUE, GL_FLOAT, sim->air->pv); + glUniform1i(glGetUniformLocation(airProg, "airP"), 2); + glActiveTexture(GL_TEXTURE0); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2d(1, 1); + glVertex3f(XRES*sdl_scale, YRES*sdl_scale, 1.0); + glTexCoord2d(0, 1); + glVertex3f(0, YRES*sdl_scale, 1.0); + glTexCoord2d(0, 0); + glVertex3f(0, 0, 1.0); + glTexCoord2d(1, 0); + glVertex3f(XRES*sdl_scale, 0, 1.0); + glEnd(); + + glUseProgram(0); + glBindTexture(GL_TEXTURE_2D, 0); + glTranslated(0, -MENUSIZE, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); + glDisable( GL_TEXTURE_2D ); +#endif +} + +void Renderer::draw_grav_zones() +{ + int x, y, i, j; + for (y=0; ygravmask[y*(XRES/CELL)+x]) + { + for (j=0; jg = g; + this->sim = sim; +#if !defined(OGLR) +#if defined(OGLI) + vid = new pixel[VIDXRES*VIDYRES]; +#else + vid = g->vid; +#endif +#endif + + memset(fire_r, 0, sizeof(fire_r)); + memset(fire_g, 0, sizeof(fire_g)); + memset(fire_b, 0, sizeof(fire_b)); + + //Set defauly display modes + SetColourMode(COLOUR_DEFAULT); + AddRenderMode(RENDER_BASC); + AddRenderMode(RENDER_FIRE); + + //Prepare the graphics cache + graphicscache = (gcache_item *)malloc(sizeof(gcache_item)*PT_NUM); + memset(graphicscache, 0, sizeof(gcache_item)*PT_NUM); + + int fireColoursCount = 4; + pixel fireColours[] = {PIXPACK(0xAF9F0F), PIXPACK(0xDFBF6F), PIXPACK(0x60300F), PIXPACK(0x000000)}; + float fireColoursPoints[] = {1.0f, 0.9f, 0.5f, 0.0f}; + + int plasmaColoursCount = 5; + pixel plasmaColours[] = {PIXPACK(0xAFFFFF), PIXPACK(0xAFFFFF), PIXPACK(0x301060), PIXPACK(0x301040), PIXPACK(0x000000)}; + float plasmaColoursPoints[] = {1.0f, 0.9f, 0.5f, 0.25, 0.0f}; + + flm_data = Graphics::GenerateGradient(fireColours, fireColoursPoints, fireColoursCount, 200); + plasma_data = Graphics::GenerateGradient(plasmaColours, plasmaColoursPoints, plasmaColoursCount, 200); + +#ifdef OGLR + //FBO Texture + glEnable(GL_TEXTURE_2D); + glGenTextures(1, &partsFboTex); + glBindTexture(GL_TEXTURE_2D, partsFboTex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, XRES, YRES, 0, GL_RGBA, GL_FLOAT, NULL); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + + //FBO + glGenFramebuffers(1, &partsFbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); + glEnable(GL_BLEND); + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, partsFboTex, 0); + glBindTexture(GL_TEXTURE_2D, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // Reset framebuffer binding + glDisable(GL_TEXTURE_2D); + + //Texture for air to be drawn + glEnable(GL_TEXTURE_2D); + glGenTextures(1, &airBuf); + glBindTexture(GL_TEXTURE_2D, airBuf); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + //Zoom texture + glEnable(GL_TEXTURE_2D); + glGenTextures(1, &zoomTex); + glBindTexture(GL_TEXTURE_2D, zoomTex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + //Texture for velocity maps for gravity + glEnable(GL_TEXTURE_2D); + glGenTextures(1, &partsTFX); + glBindTexture(GL_TEXTURE_2D, partsTFX); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + + glBindTexture(GL_TEXTURE_2D, 0); + glGenTextures(1, &partsTFY); + glBindTexture(GL_TEXTURE_2D, partsTFY); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + //Texture for velocity maps for air + //TODO: Combine all air maps into 3D array or structs + glEnable(GL_TEXTURE_2D); + glGenTextures(1, &airVX); + glBindTexture(GL_TEXTURE_2D, airVX); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + + glBindTexture(GL_TEXTURE_2D, 0); + glGenTextures(1, &airVY); + glBindTexture(GL_TEXTURE_2D, airVY); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + + glBindTexture(GL_TEXTURE_2D, 0); + glGenTextures(1, &airPV); + glBindTexture(GL_TEXTURE_2D, airPV); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + //Fire alpha texture + glEnable(GL_TEXTURE_2D); + glGenTextures(1, &fireAlpha); + glBindTexture(GL_TEXTURE_2D, fireAlpha); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, CELL*3, CELL*3, 0, GL_ALPHA, GL_FLOAT, NULL); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + //Glow alpha texture + glEnable(GL_TEXTURE_2D); + glGenTextures(1, &glowAlpha); + glBindTexture(GL_TEXTURE_2D, glowAlpha); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 11, 11, 0, GL_ALPHA, GL_FLOAT, NULL); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + + //Blur Alpha texture + glEnable(GL_TEXTURE_2D); + glGenTextures(1, &blurAlpha); + glBindTexture(GL_TEXTURE_2D, blurAlpha); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 7, 7, 0, GL_ALPHA, GL_FLOAT, NULL); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + loadShaders(); +#endif + prepare_alpha(CELL, 1.0f); +} + +void Renderer::CompileRenderMode() +{ + render_mode = 0; + for(int i = 0; i < render_modes.size(); i++) + render_mode |= render_modes[i]; +} + +void Renderer::AddRenderMode(unsigned int mode) +{ + for(int i = 0; i < render_modes.size(); i++) + { + if(render_modes[i] == mode) + { + return; + } + } + render_modes.push_back(mode); + CompileRenderMode(); +} + +void Renderer::RemoveRenderMode(unsigned int mode) +{ + for(int i = 0; i < render_modes.size(); i++) + { + if(render_modes[i] == mode) + { + render_modes.erase(render_modes.begin() + i); + i = 0; + } + } + CompileRenderMode(); +} + +void Renderer::SetRenderMode(std::vector render) +{ + render_modes = render; + CompileRenderMode(); +} + +std::vector Renderer::GetRenderMode() +{ + return render_modes; +} + +void Renderer::CompileDisplayMode() +{ + display_mode = 0; + for(int i = 0; i < display_modes.size(); i++) + display_mode |= display_modes[i]; +} + +void Renderer::AddDisplayMode(unsigned int mode) +{ + for(int i = 0; i < display_modes.size(); i++) + { + if(display_modes[i] == mode) + { + return; + } + } + display_modes.push_back(mode); + CompileDisplayMode(); +} + +void Renderer::RemoveDisplayMode(unsigned int mode) +{ + for(int i = 0; i < display_modes.size(); i++) + { + if(display_modes[i] == mode) + { + display_modes.erase(display_modes.begin() + i); + i = 0; + } + } + CompileDisplayMode(); +} + +void Renderer::SetDisplayMode(std::vector display) +{ + display_modes = display; + CompileDisplayMode(); +} + +std::vector Renderer::GetDisplayMode() +{ + return display_modes; +} + +void Renderer::SetColourMode(unsigned int mode) +{ + colour_mode = mode; +} + +unsigned int Renderer::GetColourMode() +{ + return colour_mode; +} + +Renderer::~Renderer() +{ + free(graphicscache); + free(flm_data); + free(plasma_data); +} + +#define PIXELMETHODS_CLASS Renderer + +#ifdef OGLR +#include "OpenGLDrawMethods.inc" +#else +#include "RasterDrawMethods.inc" +#endif + +#undef PIXELMETHODS_CLASS + diff --git a/src/graphics/Renderer.h b/src/graphics/Renderer.h new file mode 100644 index 0000000..b414fe4 --- /dev/null +++ b/src/graphics/Renderer.h @@ -0,0 +1,146 @@ +#ifndef RENDERER_H +#define RENDERER_H + +#include +#ifdef OGLR +#include "OpenGLHeaders.h" +#endif + +#include "Config.h" +#include "client/Client.h" +#include "simulation/Simulation.h" +#include "Graphics.h" +#include "interface/Point.h" + +class Simulation; + +class Graphics; + +struct gcache_item +{ + int isready; + int pixel_mode; + int cola, colr, colg, colb; + int firea, firer, fireg, fireb; +}; +typedef struct gcache_item gcache_item; + +class Renderer +{ +public: + std::vector render_modes; + unsigned int render_mode; + unsigned int colour_mode; + std::vector display_modes; + unsigned int display_mode; + // + unsigned char fire_r[YRES/CELL][XRES/CELL]; + unsigned char fire_g[YRES/CELL][XRES/CELL]; + unsigned char fire_b[YRES/CELL][XRES/CELL]; + unsigned int fire_alpha[CELL*3][CELL*3]; + char * flm_data; + char * plasma_data; + int emp_decor; + // + int decorations_enable; + Simulation * sim; + Graphics * g; + gcache_item *graphicscache; + + //Zoom window + ui::Point zoomWindowPosition; + ui::Point zoomScopePosition; + int zoomScopeSize; + bool zoomEnabled; + int ZFACTOR; + + //Renderers + void RenderZoom(); + void DrawWalls(); + void DrawSigns(); + void render_gravlensing(); + void render_fire(); + void prepare_alpha(int size, float intensity); + void render_parts(); + void draw_grav_zones(); + void draw_air(); + void draw_grav(); + void draw_other(); + void FinaliseParts(); + void clearScreen(float alpha); + + //class SolidsRenderer; + +#ifdef OGLR + void checkShader(GLuint shader, char * shname); + void checkProgram(GLuint program, char * progname); + void loadShaders(); +#else + pixel * vid; + void blendpixel(int x, int y, int r, int g, int b, int a); + void addpixel(int x, int y, int r, int g, int b, int a); + + void draw_icon(int x, int y, Icon icon); + + int drawtext(int x, int y, const char *s, int r, int g, int b, int a); + int drawtext(int x, int y, std::string s, int r, int g, int b, int a); + int drawchar(int x, int y, int c, int r, int g, int b, int a); + int addchar(int x, int y, int c, int r, int g, int b, int a); + + void xor_pixel(int x, int y); + void xor_line(int x, int y, int x2, int y2); + void xor_rect(int x, int y, int width, int height); + void xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h); + + void draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a); + void drawrect(int x, int y, int width, int height, int r, int g, int b, int a); + void fillrect(int x, int y, int width, int height, int r, int g, int b, int a); + void clearrect(int x, int y, int width, int height); + void gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2); + + void draw_image(pixel *img, int x, int y, int w, int h, int a); +#endif + + void drawblob(int x, int y, unsigned char cr, unsigned char cg, unsigned char cb); + //... + //Display mode modifiers + void CompileDisplayMode(); + void CompileRenderMode(); + void AddRenderMode(unsigned int mode); + void SetRenderMode(std::vector render); + std::vector GetRenderMode(); + void RemoveRenderMode(unsigned int mode); + void AddDisplayMode(unsigned int mode); + void RemoveDisplayMode(unsigned int mode); + void SetDisplayMode(std::vector display); + std::vector GetDisplayMode(); + void SetColourMode(unsigned int mode); + unsigned int GetColourMode(); + + Renderer(Graphics * g, Simulation * sim); + ~Renderer(); + +private: +#ifdef OGLR + GLuint zoomTex, airBuf, fireAlpha, glowAlpha, blurAlpha, partsFboTex, partsFbo, partsTFX, partsTFY, airPV, airVY, airVX; + GLuint fireProg, airProg_Pressure, airProg_Velocity, airProg_Cracker, lensProg; + GLuint fireV[(YRES*XRES)*2]; + GLfloat fireC[(YRES*XRES)*4]; + GLuint smokeV[(YRES*XRES)*2]; + GLfloat smokeC[(YRES*XRES)*4]; + GLuint blobV[(YRES*XRES)*2]; + GLfloat blobC[(YRES*XRES)*4]; + GLuint blurV[(YRES*XRES)*2]; + GLfloat blurC[(YRES*XRES)*4]; + GLuint glowV[(YRES*XRES)*2]; + GLfloat glowC[(YRES*XRES)*4]; + GLuint flatV[(YRES*XRES)*2]; + GLfloat flatC[(YRES*XRES)*4]; + GLuint addV[(YRES*XRES)*2]; + GLfloat addC[(YRES*XRES)*4]; + GLfloat lineV[(((YRES*XRES)*2)*6)]; + GLfloat lineC[(((YRES*XRES)*2)*6)]; +#endif +}; + +#endif diff --git a/src/interface/Appearance.h b/src/interface/Appearance.h index 6c9b24f..1749731 100644 --- a/src/interface/Appearance.h +++ b/src/interface/Appearance.h @@ -10,7 +10,7 @@ #include "Border.h" #include "Colour.h" -#include "Graphics.h" +#include "graphics/Graphics.h" namespace ui { diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp index 43e5980..ac1f87e 100644 --- a/src/interface/Button.cpp +++ b/src/interface/Button.cpp @@ -7,7 +7,7 @@ #include #include "interface/Button.h" -#include "Graphics.h" +#include "graphics/Graphics.h" #include "Engine.h" #include "Misc.h" diff --git a/src/interface/Engine.cpp b/src/interface/Engine.cpp index 2526efb..5f237a9 100644 --- a/src/interface/Engine.cpp +++ b/src/interface/Engine.cpp @@ -6,7 +6,7 @@ #include "interface/Window.h" #include "interface/Platform.h" #include "interface/Engine.h" -#include "Graphics.h" +#include "graphics/Graphics.h" using namespace ui; using namespace std; diff --git a/src/interface/Engine.h b/src/interface/Engine.h index ceabeb5..9acba62 100644 --- a/src/interface/Engine.h +++ b/src/interface/Engine.h @@ -3,7 +3,7 @@ #include #include "Singleton.h" #include "Platform.h" -#include "Graphics.h" +#include "graphics/Graphics.h" #include "Window.h" namespace ui diff --git a/src/interface/SaveButton.cpp b/src/interface/SaveButton.cpp index e1aeac5..ee57e81 100644 --- a/src/interface/SaveButton.cpp +++ b/src/interface/SaveButton.cpp @@ -2,7 +2,7 @@ #include "SaveButton.h" #include "client/SaveInfo.h" -#include "Graphics.h" +#include "graphics/Graphics.h" #include "Engine.h" #include "client/Client.h" #include "simulation/SaveRenderer.h" diff --git a/src/interface/SaveButton.h b/src/interface/SaveButton.h index 2220f1c..02795fb 100644 --- a/src/interface/SaveButton.h +++ b/src/interface/SaveButton.h @@ -6,7 +6,7 @@ #include "Component.h" #include "client/SaveFile.h" #include "client/SaveInfo.h" -#include "Graphics.h" +#include "graphics/Graphics.h" #include "search/Thumbnail.h" #include "interface/Colour.h" diff --git a/src/powdertoyjava/PowderToyJava.cpp b/src/powdertoyjava/PowderToyJava.cpp index bcc9344..835fdc4 100644 --- a/src/powdertoyjava/PowderToyJava.cpp +++ b/src/powdertoyjava/PowderToyJava.cpp @@ -7,7 +7,7 @@ #include "Config.h" #include "PowderToyJava.h" -#include "Graphics.h" +#include "graphics/Graphics.h" #include "game/GameController.h" diff --git a/src/render/RenderController.h b/src/render/RenderController.h index 81e29c2..37592ac 100644 --- a/src/render/RenderController.h +++ b/src/render/RenderController.h @@ -10,7 +10,7 @@ #include "RenderView.h" #include "RenderModel.h" -#include "Renderer.h" +#include "graphics/Renderer.h" #include "Controller.h" class RenderView; diff --git a/src/render/RenderModel.h b/src/render/RenderModel.h index 6bdf36e..7d25f50 100644 --- a/src/render/RenderModel.h +++ b/src/render/RenderModel.h @@ -10,7 +10,7 @@ #include #include "RenderView.h" -#include "Renderer.h" +#include "graphics/Renderer.h" using namespace std; diff --git a/src/render/RenderView.cpp b/src/render/RenderView.cpp index f0868a3..7bf5bf2 100644 --- a/src/render/RenderView.cpp +++ b/src/render/RenderView.cpp @@ -6,8 +6,8 @@ */ #include "simulation/ElementGraphics.h" -#include "Graphics.h" -#include "Renderer.h" +#include "graphics/Graphics.h" +#include "graphics/Renderer.h" #include "RenderView.h" class RenderView::RenderModeAction: public ui::CheckboxAction diff --git a/src/render/RenderView.h b/src/render/RenderView.h index 487a53e..c084916 100644 --- a/src/render/RenderView.h +++ b/src/render/RenderView.h @@ -13,7 +13,7 @@ #include "interface/Window.h" #include "RenderController.h" #include "RenderModel.h" -#include "Renderer.h" +#include "graphics/Renderer.h" #include "interface/Checkbox.h" class RenderController; diff --git a/src/search/Thumbnail.h b/src/search/Thumbnail.h index 25c0985..d951a96 100644 --- a/src/search/Thumbnail.h +++ b/src/search/Thumbnail.h @@ -2,7 +2,7 @@ #define THUMBNAIL_H #include -#include "Graphics.h" +#include "graphics/Graphics.h" #include "interface/Point.h" class Thumbnail diff --git a/src/simulation/Element.h b/src/simulation/Element.h index 7cd379e..3c28e2f 100644 --- a/src/simulation/Element.h +++ b/src/simulation/Element.h @@ -4,7 +4,7 @@ #include #include "Simulation.h" -#include "Renderer.h" +#include "graphics/Renderer.h" #include "Gravity.h" #include "Misc.h" #include "ElementGraphics.h" diff --git a/src/simulation/SaveRenderer.cpp b/src/simulation/SaveRenderer.cpp index 2a79e79..73b486e 100644 --- a/src/simulation/SaveRenderer.cpp +++ b/src/simulation/SaveRenderer.cpp @@ -6,9 +6,9 @@ */ #include "SaveRenderer.h" -#include "Graphics.h" +#include "graphics/Graphics.h" #include "Simulation.h" -#include "Renderer.h" +#include "graphics/Renderer.h" SaveRenderer::SaveRenderer(){ diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp index 1ce471f..01d388f 100644 --- a/src/simulation/Sign.cpp +++ b/src/simulation/Sign.cpp @@ -6,7 +6,7 @@ */ #include "Sign.h" -#include "Graphics.h" +#include "graphics/Graphics.h" #include "Misc.h" sign::sign(std::string text_, int x_, int y_, Justification justification_): diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index b9cc6bb..e4e4120 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -10,8 +10,8 @@ #include #include #include "Config.h" -#include "Renderer.h" -#include "Graphics.h" +#include "graphics/Renderer.h" +#include "graphics/Graphics.h" //#include "Elements.h" #include "Tools.h" #include "Misc.h" diff --git a/src/simulation/elements/Element.h b/src/simulation/elements/Element.h index b584506..29c7fa0 100644 --- a/src/simulation/elements/Element.h +++ b/src/simulation/elements/Element.h @@ -2,7 +2,7 @@ #define ELEMENTCLASS_H #include "simulation/Simulation.h" -#include "Renderer.h" +#include "graphics/Renderer.h" #include "simulation/Elements.h" class Simulation; diff --git a/src/simulation/tools/SimTool.h b/src/simulation/tools/SimTool.h index 0fbcba4..ed4cbcd 100644 --- a/src/simulation/tools/SimTool.h +++ b/src/simulation/tools/SimTool.h @@ -2,7 +2,7 @@ #define SIMTOOL_H #include "simulation/Simulation.h" -#include "Renderer.h" +#include "graphics/Renderer.h" #include "simulation/Elements.h" class Simulation; -- cgit v0.9.2-21-gd62e