Skip to content

Instantly share code, notes, and snippets.

@georgelima
Created April 18, 2018 13:41
Show Gist options
  • Save georgelima/9ad2a752a364d008f2a6ea4ce7fef555 to your computer and use it in GitHub Desktop.
Save georgelima/9ad2a752a364d008f2a6ea4ce7fef555 to your computer and use it in GitHub Desktop.
OpenGL
#include <GL/glut.h>
#include <stdlib.h>
void init(void);
void display(void);
void keyboard(unsigned char key, int x, int y);
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(1000, 1000);
glutInitWindowPosition(100, 100);
glutCreateWindow("Exercicio 02");
init();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
void init(void){
glClearColor(0.0, 0.0, 0.0, 1.0);
glOrtho(0, 256, 0, 256, -1, 1);
}
void drawStar(int size) {
glVertex2f(20.0f * size, 20.0f * size); // 1
glVertex2f(40.0f * size, 80.0f * size); // 2
glVertex2f(40.0f * size, 80.0f * size); // 2
glVertex2f(60.0f * size, 20.0f * size); // 3
glVertex2f(60.0f * size, 20.0f * size); // 3
glVertex2f(10.0f * size, 55.0f * size); // 4
glVertex2f(10.0f * size, 55.0f * size); // 4
glVertex2f(70.0f * size, 55.0f * size); // 5
glVertex2f(70.0f * size, 55.0f * size); // 5
glVertex2f(20.0f * size, 20.0f * size); // 6
}
void drawHorizontalLine(float x) {
glVertex2f(x, 20.0f);
glVertex2f(x, 40.0f);
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glBegin(GL_LINES);
//inicio
//Estrela
// G
drawHorizontalLine(20.0f);
glVertex2f(20.0f, 20.0f);
glVertex2f(30.0f, 20.0f);
glVertex2f(20.0f, 40.0f);
glVertex2f(30.0f, 40.0f);
glVertex2f(30.0f, 20.0f);
glVertex2f(30.0f, 30.0f);
glVertex2f(25.0f, 30.0f);
glVertex2f(30.0f, 30.0f);
// E
drawHorizontalLine(35.0f);
glVertex2f(35.0f, 20.0f);
glVertex2f(45.0f, 20.0f);
glVertex2f(35.0f, 30.0f);
glVertex2f(45.0f, 30.0f);
glVertex2f(35.0f, 40.0f);
glVertex2f(45.0f, 40.0f);
// O
drawHorizontalLine(50.0f);
glVertex2f(50.0f, 20.0f);
glVertex2f(60.0f, 20.0f);
drawHorizontalLine(60.0f);
glVertex2f(50.0f, 40.0f);
glVertex2f(60.0f, 40.0f);
// G
drawHorizontalLine(65.0f);
glVertex2f(65.0f, 20.0f);
glVertex2f(75.0f, 20.0f);
glVertex2f(65.0f, 40.0f);
glVertex2f(75.0f, 40.0f);
glVertex2f(75.0f, 20.0f);
glVertex2f(75.0f, 30.0f);
glVertex2f(70.0f, 30.0f);
glVertex2f(75.0f, 30.0f);
// E
drawHorizontalLine(80.0f);
glVertex2f(80.0f, 20.0f);
glVertex2f(90.0f, 20.0f);
glVertex2f(80.0f, 30.0f);
glVertex2f(90.0f, 30.0f);
glVertex2f(80.0f, 40.0f);
glVertex2f(90.0f, 40.0f);
drawStar(1);
// fim
glEnd();
glFlush();
}
void keyboard(unsigned char key, int x, int y){
switch(key){
case 27:
exit(0);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment