Created
April 25, 2010 08:25
-
-
Save bhelyer/378273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <GL/gl.h> | |
#include <GL/glut.h> | |
const GLfloat vertices[] = {-1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f}; | |
GLuint vertexBuffer; | |
const GLuint elements[] = {0, 1, 2, 3}; | |
GLuint elementBuffer; | |
void render(); | |
int main(int argc, char* argv[]) | |
{ | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); | |
glutInitWindowSize(400, 300); | |
glutCreateWindow("SimpleGL"); | |
glutDisplayFunc(&render); | |
glGenBuffers(1, &vertexBuffer); | |
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); | |
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); | |
glGenBuffers(1, &elementBuffer); | |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer); | |
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW); | |
glutMainLoop(); | |
return 0; | |
} | |
void render() | |
{ | |
glClearColor(0.2f, 0.2f, 0.2f, 1.0f); | |
glClear(GL_COLOR_BUFFER_BIT); | |
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); | |
glVertexPointer(2, GL_FLOAT, sizeof(GLfloat) * 2, (void*)0); | |
glEnableClientState(GL_VERTEX_ARRAY); | |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer); | |
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, (void*)0); | |
glDisableClientState(GL_VERTEX_ARRAY); | |
glutSwapBuffers(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module simplegl; | |
import c.gl; | |
import c.glut; | |
const GLfloat[] vertices = [-1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f]; | |
__gshared GLuint vertexBuffer; | |
const GLuint[] elements = [0, 1, 2, 3]; | |
__gshared GLuint elementBuffer; | |
void main() | |
{ | |
int argc = 1; | |
char*[] argv = ["./dummyexe".dup.ptr]; | |
glutInit(&argc, argv.ptr); | |
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); | |
glutInitWindowSize(400, 300); | |
glutCreateWindow("SimpleGL"); | |
glutDisplayFunc(&render); | |
glGenBuffers(1, &vertexBuffer); | |
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); | |
glBufferData(GL_ARRAY_BUFFER, vertices.sizeof, vertices.ptr, GL_STATIC_DRAW); | |
glGenBuffers(1, &elementBuffer); | |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer); | |
glBufferData(GL_ELEMENT_ARRAY_BUFFER, elements.sizeof, elements.ptr, GL_STATIC_DRAW); | |
glutMainLoop(); | |
} | |
void render() | |
{ | |
glClearColor(0.2f, 0.2f, 0.2f, 1.0f); | |
glClear(GL_COLOR_BUFFER_BIT); | |
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); | |
glVertexPointer(2, GL_FLOAT, GLfloat.sizeof * 2, cast(void*)0); | |
glEnableClientState(GL_VERTEX_ARRAY); | |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer); | |
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, cast(void*)0); | |
glDisableClientState(GL_VERTEX_ARRAY); | |
glutSwapBuffers(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment