Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SDL/SDL.h" // Headers
- #include "SDL/SDL_opengl.h"
- #include <iostream>
- int main(int argc, char* args[]) // Init
- {
- SDL_Init(SDL_INIT_EVERYTHING); // Init SDL
- SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8); // OpenGL Memory Usage
- SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);
- SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, 32);
- SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);
- SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1);
- SDL_WM_SetCaption( "WutFuckbuttWitty", NULL ); // Caption of the Window
- SDL_SetVideoMode(320,240,32, SDL_OPENGL); // Size of the Window
- glClearColor(0,0,0,1); //RGBA Clear color.
- glViewport(0,0,320,240); //Viewport portion
- glShadeModel(GL_SMOOTH); //Shader Model - Smooth
- glMatrixMode(GL_PROJECTION); // 2D Rendering
- glLoadIdentity(); // Save it
- glDisable(GL_DEPTH_TEST); // Disable Depth Checking
- bool isRunning = true; // Loop state
- SDL_Event event; // Event handler
- while (isRunning) // Main Game Loop
- {
- //Events
- while (SDL_PollEvent(&event))
- { // Logic for certain event
- if (event.type == SDL_QUIT)
- {
- isRunning = false;
- }
- if(event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE)
- {
- isRunning = false;
- }
- if(event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_SPACE)
- {
- glClearColor(1,1,1,1);
- }
- }
- //Logic
- //Rendering
- glClear(GL_COLOR_BUFFER_BIT); // Clear screen
- glPushMatrix(); // Start Rendering
- glOrtho(0, 320, 240, 0, -1, -1); // Set the Matrix
- glColor4ub(255, 0, 255, 255);
- glBegin(GL_QUADS);
- glVertex2f(5,5);
- glVertex2f(315, 5);
- glVertex2f(315, 235);
- glVertex2f(5, 235);
- glEnd();
- glPopMatrix(); // Stop Rendering
- SDL_GL_SwapBuffers(); // Push Output(frame) to the screen
- }
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement