Skip to content

Instantly share code, notes, and snippets.

@anunyin
Created March 12, 2013 18:44
Show Gist options
  • Save anunyin/5145718 to your computer and use it in GitHub Desktop.
Save anunyin/5145718 to your computer and use it in GitHub Desktop.
ShaderlessOpenGL
#include <SDL.h>
#include <Windows.h>
#include <gl/glew.h>
#include <gl/GL.h>
#include <stdexcept>
#undef main
struct Vector3 {
float x, y, z;
Vector3(float _x, float _y, float _z) {
x = _x;
y = _y;
z = _z;
}
};
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_SetVideoMode(800, 600, 16, SDL_OPENGL);
SDL_Event event;
GLenum status = glewInit();
if (status != GLEW_OK)
throw std::runtime_error(reinterpret_cast<const GLchar*>(status));
Vector3 vertices[] = {
Vector3(0.0f, 1.0f, 0.0f),
Vector3(-1.0f, -1.0f, 0.0f),
Vector3(1.0f, -1.0f, 0.0f),
};
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
bool running = true;
while (running) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT)
running = false;
else if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_F4 && SDL_GetModState() & KMOD_ALT)
running = false;
}
}
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3);
SDL_GL_SwapBuffers();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment