Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- OpenGL visualization skeleton for displaying bitmap images. Just provide a GenerateImage function.
- Good starting point for all image processing exercises for parallel programming.
- Example of generating bitmaps using GenerateImage and the prepared GLUT OpenGL visualization.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #ifdef __APPLE__
- #include <GLUT/glut.h>
- #else
- #include <GL/freeglut.h>
- #include <GL/freeglut_ext.h>
- #endif
- typedef struct {
- GLbyte r;
- GLbyte g;
- GLbyte b;
- } pixel;
- typedef struct{
- int x;
- int y;
- } vertex;
- // postupnost bodov, najprv 3 potom 2
- //treba vedet zobrazit pole (postupnost)
- //vertex[] pole = { {1,2,3}, {4,5}, {6,7}};
- #define TEX_SIZE 512
- pixel image[TEX_SIZE][TEX_SIZE];
- GLuint texture;
- int mocnina(int a, int b)
- {
- return (int) pow(a,b);
- }
- void GenerateImage() {
- int x,y;
- pixel black;
- black.r = 0;
- black.g = 0;
- black.b = 0;
- float u;
- for (x = 0; x < TEX_SIZE; x++)
- for (y = 0; y < TEX_SIZE; y++)
- image[x][y].r = image[x][y].b = image[x][y].g = 255;
- int Vy1 = 130;
- int Vx1 = 130;
- int Vx2 = 50;
- int Vy2 = 50;
- int Qx, Qy;
- for (u = 0; u < 1; u += 0.01) {
- Qy = (1 - u) * Vy1 + Vy2;
- Qx = (1 - u) * Vx1 + Vx2;
- image[Qx][Qy] = black;
- }
- int matrix[4][4] = {-1,3,-1,1,3,-6,3,0,-3,3,0,0,1,0,0,0};
- float ucka[4] = {0,0,0,0};
- vertex vertices[4];
- vertex v0;
- vertex v1;
- vertex v2;
- v0.x = 130;
- v0.y = 130;
- v1.x = 50;
- v1.y = 50;
- v2.x = 20;
- v2.y = 20;
- for (u = 0; u < 1; u += 0.1) {
- }
- }
- // Initialize OpenGL state
- void init() {
- // Texture setup
- glEnable(GL_TEXTURE_2D);
- glGenTextures( 1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- // Other
- glClearColor(0,0,0,0);
- gluOrtho2D(-1,1,-1,1);
- glLoadIdentity();
- glColor3f(1,1,1);
- }
- // Generate and display the image.
- void display() {
- // Call user image generation
- GenerateImage();
- // Copy image to texture memory
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEX_SIZE, TEX_SIZE, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
- // Clear screen buffer
- glClear(GL_COLOR_BUFFER_BIT);
- // Render a quad
- glBegin(GL_QUADS);
- glTexCoord2f(1,0); glVertex2f(1,-1);
- glTexCoord2f(1,1); glVertex2f(1,1);
- glTexCoord2f(0,1); glVertex2f(-1,1);
- glTexCoord2f(0,0); glVertex2f(-1,-1);
- glEnd();
- // Display result
- glFlush();
- glutPostRedisplay();
- glutSwapBuffers();
- }
- // Main entry function
- int main(int argc, char ** argv) {
- // Init GLUT
- glutInit(&argc, argv);
- glutInitWindowSize(TEX_SIZE, TEX_SIZE);
- glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
- glutCreateWindow("OpenGL Window");
- // Set up OpenGL state
- init();
- // Run the control loop
- glutDisplayFunc(display);
- glutMainLoop();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement