Created
September 25, 2012 15:42
-
-
Save kenpower/3782664 to your computer and use it in GitHub Desktop.
Drawing a triangle in pixel space in SFML/OpenGL
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
while (App.isOpen()) | |
{ | |
// Process events | |
sf::Event Event; | |
while (App.pollEvent(Event)) | |
{ | |
// Close window : exit | |
if (Event.type == sf::Event::Closed) | |
App.close(); | |
// Escape key : exit | |
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape)) | |
App.close(); | |
} | |
//Prepare for drawing | |
// Clear color and depth buffer | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
//select projection nmatrix | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity();//reset marix | |
glOrtho(0,800,0,600,0,1); //choose an orthographic projection | |
//same size as window | |
//coordinates will have a 1-1 correspondance with pixels | |
//draw an orange triangle | |
glColor3d(1,0.5,0); | |
glBegin(GL_TRIANGLES); | |
glVertex2d(0,0); | |
glVertex2d(400,0); | |
glVertex2d(400,300); | |
glEnd(); | |
App.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment