Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef __APPLE__
- #include <GLUT/glut.h>
- #else
- #include <GL/glut.h>
- #endif
- #include<string>
- #include<sstream>
- #include <stdlib.h>
- void RenderNormalFont(float x, float y, const char * str){
- const char * c;
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -1.0f);
- glColor3f(0.0f,0.0f,0.0f);
- glRasterPos2f(x,y);
- for(c=str; *c!='\0'; c++){
- glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *c);
- }
- }
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glScalef(0.3f,0.3f,0.3f);
- glLineWidth(2.0);
- glBegin(GL_QUADS);
- glColor3f(1.0f,2.0f,1.0f);
- glVertex2i(5,5);
- glVertex2i(-5,5);
- glVertex2i(-5,-5);
- glVertex2i(5,-5);
- glEnd();
- glScalef(0.5f,0.5f,0.5f);
- glBegin(GL_LINE_STRIP);
- glColor3f(2.0f,0.0f,0.0f);
- glVertex2f(-3.5f,6.0f);
- glVertex2f(-3.5f,-3.5f);
- glVertex2f(3.5f,-3.5f);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(1.0f,0.0f,0.0f);
- glVertex2f(-3.0f,0.5f);
- glVertex2f(-3.0f,-3.5f);
- glVertex2f(-2.5f,-3.5f);
- glVertex2f(-2.5f,0.5f);
- glVertex2f(-2.0f,5.5f);
- glVertex2f(-2.0f,-3.5f);
- glVertex2f(-1.5f,-3.5f);
- glVertex2f(-1.5f,5.5f);
- glVertex2f(-1.0f,-1.5f);
- glVertex2f(-1.0f,-3.5f);
- glVertex2f(-0.5f,-3.5f);
- glVertex2f(-0.5f,-1.5f);
- glVertex2f(0.0f,2.5f);
- glVertex2f(0.0f,-3.5f);
- glVertex2f(0.5f,-3.5f);
- glVertex2f(0.5f,2.5f);
- glEnd();
- RenderNormalFont(-0.43f,0.0f,"4");
- RenderNormalFont(-0.27f,0.7f,"9");
- RenderNormalFont(-0.12f,-0.3f,"2");
- RenderNormalFont(0.035f,0.27f,"6");
- float posy = -0.53f;
- int foo = 0;
- for(foo=0; foo <= 9; foo++)
- {
- std::ostringstream strm;
- strm << foo;
- std::string numStr = strm.str();
- char const * ca = numStr.c_str();
- RenderNormalFont(-0.58f, posy, ca);
- posy +=0.15;
- }
- glLoadIdentity();
- glutSwapBuffers();
- }
- void mouse(int button, int state, int x, int y) {
- switch (button) {
- case GLUT_LEFT_BUTTON:
- if (state == GLUT_DOWN)
- exit(0);
- break;
- }
- }
- void keyboard(unsigned char key, int x,int y)
- {}
- static void idle(void)
- {
- glutPostRedisplay();
- }
- int main(int argc, char *argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(900, 900);
- glutInitWindowPosition (100, 100);
- glutCreateWindow("Assignment 1");
- glutDisplayFunc(display);
- glutMouseFunc(mouse);
- glutKeyboardFunc(keyboard);
- glutIdleFunc(idle);
- glutMainLoop();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment