Pastafarianist

OpenGL Textures full code

Jul 30th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.10 KB | None | 0 0
  1. {$apptype GUI}
  2.  
  3. uses Gl,Glu,Glut;
  4.  
  5. const width = 600;
  6.       height = 600;
  7.      
  8.       res_y = 200;
  9.       res_x = 200;
  10.  
  11. var torot, torot1, torot2: double;
  12.     texture_id: GLuint;
  13.  
  14. procedure drawSphere;
  15.   var sphere: PGLUquadricObj;
  16. begin
  17.   sphere := gluNewQuadric();
  18.   gluQuadricTexture(sphere, GL_TRUE);
  19.     gluSphere(sphere, 50.0, 20, 20);
  20.   gluDeleteQuadric(sphere);
  21. end;
  22.  
  23. procedure display(); cdecl;
  24. begin
  25. glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  26. gLLoadIdentity();
  27. glRotatef(torot, 0, 1, 0);
  28.  
  29. glBindTexture(GL_TEXTURE_2D, texture_id);
  30. drawSphere();
  31.  
  32. glFlush();
  33. glutSwapBuffers();
  34. end;
  35.  
  36. function prepareTexture: GLuint;
  37.     var texture_data: array [0..res_y - 1, 0..res_x - 1, 0..2] of byte;
  38.             texture_id: GLuint;
  39.             x, y: integer;
  40. begin
  41.   for y := 0 to res_y - 1 do begin
  42.     for x := 0 to res_x - 1 do begin
  43.       texture_data[y, x, 0] := random(256);
  44.       texture_data[y, x, 1] := random(256);
  45.       texture_data[y, x, 2] := random(256);
  46.     end;
  47.   end;
  48.   glEnable(GL_TEXTURE_2D);
  49.   glGenTextures(1, @texture_id);
  50.   glBindTexture(GL_TEXTURE_2D, texture_id);
  51.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  52.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  53.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  54.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  55.   glTexImage2D(GL_TEXTURE_2D, 0, 3, res_x, res_y, 0, GL_RGB, GL_UNSIGNED_BYTE, @texture_data);
  56.   prepareTexture := texture_id;
  57. end;
  58.  
  59. procedure initGl;
  60. begin
  61. glClearColor(0.0,0.0,0.0,0.0);
  62. glMatrixMode(GL_projection);
  63. glLoadIdentity;
  64. glOrtho(-200, 200, -200, 200, -200, 200);
  65. glMatrixMode(GL_MODELVIEW);
  66. glLoadIdentity();
  67. glClearDepth(1.0);
  68. glEnable(GL_LEQUAL);
  69. END;
  70.  
  71. procedure keyboard(code:byte;x,y:longint); cdecl;
  72. begin
  73. case code of
  74. 27:halt;
  75. end;
  76. end;
  77.  
  78. procedure initgLUT;
  79. BEGIN
  80. glutInitDisplayMode(GLUT_DOUBLE or GLUT_RGB);
  81. glutInitWindowSize(width,height);
  82. glutCreateWindow('DOLBOEB');
  83. glutDisplayFunc(@display);
  84. glutKeyboardFunc(@keyboard);
  85. end;
  86. begin
  87. initGlut;initGL;
  88. texture_id := preparetexture;
  89. glutMainLoop();
  90. end.
Add Comment
Please, Sign In to add comment