sak1b

TEXT on screen

Dec 29th, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #include<windows.h>
  2. #ifdef __APPLE__
  3. #include <GLUT/glut.h>
  4. #else
  5. #include <GL/glut.h>
  6. #endif
  7.  
  8. #include "GL/glu.h"
  9. //glm not required
  10. //#include <glm.hpp>
  11. //#include <gtc/matrix_transform.hpp>
  12. #include <string>
  13.  
  14. int win_width = 500, win_height = 500;
  15.  
  16. void renderScene(void) {
  17.  
  18. static float dis=0, ddis=0, elev=0, delev=0, azim=0, dazim=0;
  19.  
  20. azim += 0.5f;
  21. if (azim >= 360.0f){
  22. azim -= 360.0f;
  23. }
  24.  
  25. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  26.  
  27. glLoadIdentity();
  28. glTranslatef(0.0f, 0.0f, -(dis + ddis));
  29. glRotated(elev + delev, 1.0, 0.0, 0.0);
  30. glRotated(azim + dazim, 0.0, 1.0, 0.0);
  31. glScalef(2.0f,2.0f,2.0f);
  32.  
  33. glBegin(GL_TRIANGLES);
  34. glColor3f(1.0f, 1.0f, 0.0f);
  35. glVertex3f(-0.5f, -0.5f, 0.0f);
  36. glColor3f(0.0f, 1.0f, 0.0f);
  37. glVertex3f(0.5f, 0.0f, 0.0f);
  38. glColor3f(0.0f, 0.0f, 1.0f);
  39. glVertex3f(0.0f, 0.5f, 0.0f);
  40. glEnd();
  41.  
  42.  
  43. glMatrixMode(GL_PROJECTION);
  44. glPushMatrix();
  45. glLoadIdentity();
  46. //I like to use glm because glu is deprecated
  47. //glm::mat4 orth= glm::ortho(0.0f, (float)win_width, 0.0f, (float)win_height);
  48. //glMultMatrixf(&(orth[0][0]));
  49. gluOrtho2D(0.0, win_width, 0.0, win_height);
  50. glMatrixMode(GL_MODELVIEW);
  51. glPushMatrix();
  52. glLoadIdentity();
  53. glColor3f(1.0f, 0.0f, 0.0f);//needs to be called before RasterPos
  54. glRasterPos2i(150, 150);
  55. std::string s = "Hello Miraz bhai";
  56. // void * font = GLUT_BITMAP_9_BY_15;
  57. void * font = GLUT_BITMAP_TIMES_ROMAN_24;
  58.  
  59. for (std::string::iterator i = s.begin(); i != s.end(); ++i)
  60. {
  61. char c = *i;
  62. //this does nothing, color is fixed for Bitmaps when calling glRasterPos
  63. //glColor3f(1.0, 0.0, 1.0);
  64. glutBitmapCharacter(font, c);
  65. }
  66. glMatrixMode(GL_MODELVIEW);
  67. glPopMatrix();
  68. glMatrixMode(GL_PROJECTION);
  69. glPopMatrix();
  70. glEnable(GL_TEXTURE_2D);
  71.  
  72. glutSwapBuffers();
  73. glutPostRedisplay();
  74. }
  75.  
  76. int main(int argc, char **argv) {
  77.  
  78. // init GLUT and create Window
  79. glutInit(&argc, argv);
  80. glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  81. glutInitWindowPosition(100, 100);
  82. glutInitWindowSize(win_width, win_height);
  83. glutCreateWindow("GLUT Test");
  84.  
  85. // register callbacks
  86. glutDisplayFunc(renderScene);
  87.  
  88. // enter GLUT event processing cycle
  89. glutMainLoop();
  90.  
  91. return 1;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment