| 42 | } |
| 43 | |
| 44 | int main(int argc, char *argv[]) |
| 45 | { |
| 46 | SDL_Surface *screen; |
| 47 | |
| 48 | // Slightly different SDL initialization |
| 49 | if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) { |
| 50 | printf("Unable to initialize SDL: %s\n", SDL_GetError()); |
| 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new* |
| 55 | |
| 56 | screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ); // *changed* |
| 57 | if ( !screen ) { |
| 58 | printf("Unable to set video mode: %s\n", SDL_GetError()); |
| 59 | return 1; |
| 60 | } |
| 61 | |
| 62 | // Check extensions |
| 63 | |
| 64 | const char *exts = (const char *)glGetString(GL_EXTENSIONS); |
| 65 | assert(hasext(exts, "GL_ARB_texture_compression")); |
| 66 | assert(hasext(exts, "GL_EXT_texture_compression_s3tc")); |
| 67 | |
| 68 | // Set the OpenGL state after creating the context with SDL_SetVideoMode |
| 69 | |
| 70 | glClearColor( 0, 0, 0, 0 ); |
| 71 | |
| 72 | glEnable( GL_TEXTURE_2D ); // Needed when we're using the fixed-function pipeline. |
| 73 | |
| 74 | glViewport( 0, 0, 640, 480 ); |
| 75 | |
| 76 | glMatrixMode( GL_PROJECTION ); |
| 77 | GLfloat matrixData[] = { 2.0/640, 0, 0, 0, |
| 78 | 0, -2.0/480, 0, 0, |
| 79 | 0, 0, -1, 0, |
| 80 | -1, 1, 0, 1 }; |
| 81 | glLoadMatrixf(matrixData); // test loadmatrix |
| 82 | |
| 83 | glMatrixMode( GL_MODELVIEW ); |
| 84 | glLoadIdentity(); |
| 85 | |
| 86 | |
| 87 | // Load the OpenGL texture |
| 88 | |
| 89 | GLuint texture; |
| 90 | |
| 91 | #define DDS_SIZE 262272 |
| 92 | FILE *dds = fopen("screenshot.dds", "rb"); |
| 93 | char *ddsdata = (char*)malloc(512*512*4); // DDS_SIZE |
| 94 | assert(fread(ddsdata, 1, DDS_SIZE, dds) == DDS_SIZE); |
| 95 | fclose(dds); |
| 96 | |
| 97 | glGenTextures( 1, &texture ); |
| 98 | glBindTexture( GL_TEXTURE_2D, texture ); |
| 99 | |
| 100 | assert(!glGetError()); |
| 101 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 512, 512, 0, DDS_SIZE-128, ddsdata+128); |