Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. /*
  2. OpenGL visualization skeleton for displaying bitmap images. Just provide a GenerateImage function.
  3. Good starting point for all image processing exercises for parallel programming.
  4.  
  5. Example of generating bitmaps using GenerateImage and the prepared GLUT OpenGL visualization.
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11.  
  12. #ifdef __APPLE__
  13. #include <GLUT/glut.h>
  14. #else
  15. #include <GL/freeglut.h>
  16. #include <GL/freeglut_ext.h>
  17. #endif
  18.  
  19. typedef struct {
  20. GLbyte r;
  21. GLbyte g;
  22. GLbyte b;
  23. } pixel;
  24.  
  25. typedef struct{
  26. int x;
  27. int y;
  28. } vertex;
  29.  
  30.  
  31. // postupnost bodov, najprv 3 potom 2
  32. //treba vedet zobrazit pole (postupnost)
  33. //vertex[] pole = { {1,2,3}, {4,5}, {6,7}};
  34.  
  35. #define TEX_SIZE 512
  36. pixel image[TEX_SIZE][TEX_SIZE];
  37.  
  38. GLuint texture;
  39.  
  40. int mocnina(int a, int b)
  41. {
  42. return (int) pow(a,b);
  43. }
  44.  
  45. void GenerateImage() {
  46.  
  47. int x,y;
  48. pixel black;
  49. black.r = 0;
  50. black.g = 0;
  51. black.b = 0;
  52. float u;
  53.  
  54. for (x = 0; x < TEX_SIZE; x++)
  55. for (y = 0; y < TEX_SIZE; y++)
  56. image[x][y].r = image[x][y].b = image[x][y].g = 255;
  57.  
  58. int Vy1 = 130;
  59. int Vx1 = 130;
  60. int Vx2 = 50;
  61. int Vy2 = 50;
  62. int Qx, Qy;
  63.  
  64. for (u = 0; u < 1; u += 0.01) {
  65. Qy = (1 - u) * Vy1 + Vy2;
  66. Qx = (1 - u) * Vx1 + Vx2;
  67. image[Qx][Qy] = black;
  68. }
  69.  
  70. int matrix[4][4] = {-1,3,-1,1,3,-6,3,0,-3,3,0,0,1,0,0,0};
  71. float ucka[4] = {0,0,0,0};
  72. vertex vertices[4];
  73.  
  74. vertex v0;
  75. vertex v1;
  76. vertex v2;
  77.  
  78. v0.x = 130;
  79. v0.y = 130;
  80. v1.x = 50;
  81. v1.y = 50;
  82. v2.x = 20;
  83. v2.y = 20;
  84.  
  85. for (u = 0; u < 1; u += 0.1) {
  86.  
  87. }
  88.  
  89. }
  90.  
  91. // Initialize OpenGL state
  92. void init() {
  93. // Texture setup
  94. glEnable(GL_TEXTURE_2D);
  95. glGenTextures( 1, &texture);
  96. glBindTexture(GL_TEXTURE_2D, texture);
  97. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  98. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  99. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  100. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  101.  
  102. // Other
  103. glClearColor(0,0,0,0);
  104. gluOrtho2D(-1,1,-1,1);
  105. glLoadIdentity();
  106. glColor3f(1,1,1);
  107. }
  108.  
  109. // Generate and display the image.
  110. void display() {
  111. // Call user image generation
  112. GenerateImage();
  113. // Copy image to texture memory
  114. glBindTexture(GL_TEXTURE_2D, texture);
  115. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEX_SIZE, TEX_SIZE, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
  116. // Clear screen buffer
  117. glClear(GL_COLOR_BUFFER_BIT);
  118. // Render a quad
  119. glBegin(GL_QUADS);
  120. glTexCoord2f(1,0); glVertex2f(1,-1);
  121. glTexCoord2f(1,1); glVertex2f(1,1);
  122. glTexCoord2f(0,1); glVertex2f(-1,1);
  123. glTexCoord2f(0,0); glVertex2f(-1,-1);
  124. glEnd();
  125. // Display result
  126. glFlush();
  127. glutPostRedisplay();
  128. glutSwapBuffers();
  129. }
  130.  
  131. // Main entry function
  132. int main(int argc, char ** argv) {
  133. // Init GLUT
  134. glutInit(&argc, argv);
  135. glutInitWindowSize(TEX_SIZE, TEX_SIZE);
  136. glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
  137. glutCreateWindow("OpenGL Window");
  138. // Set up OpenGL state
  139. init();
  140. // Run the control loop
  141. glutDisplayFunc(display);
  142. glutMainLoop();
  143. return EXIT_SUCCESS;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement