Advertisement
Guest User

Untitled

a guest
Dec 21st, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include <GL/gl.h>
  5. #include <GL/glu.h>
  6. #include <GL/glut.h>
  7.  
  8. void drawPixel(int x, int y, int r, int g, int b);
  9. void render(void);
  10.  
  11. int main(int argc, char** argv){
  12.     glutInit(&argc, argv);
  13.     glutInitDisplayMode(GLUT_SINGLE);
  14.     glutInitWindowSize(600, 400);
  15.     glutInitWindowPosition(100, 100);
  16.     glutCreateWindow("Game");
  17.     glutDisplayFunc(render);
  18.     glutMainLoop();
  19.        
  20. return 0;
  21. }
  22.  
  23. void render(void) {
  24.         glClearColor(0.12, 0.12, 0.13, 0.1);
  25.         glClear(GL_COLOR_BUFFER_BIT);
  26.         glFlush();
  27.        
  28.         int x = 0; int y = 0;
  29.        
  30.         /*
  31.         do{
  32.                 drawPixel(x, y, 255, 35, 32);
  33.                 x++;
  34.                
  35.                 if(x == 800) { x = 0; y++; glFlush();}
  36.             }while(y != 640);
  37.             */
  38.                
  39.         drawPixel(20, 400, 0, 255, 255);
  40.        
  41.        
  42.         glFlush();
  43.     }
  44.  
  45. void drawPixel(int x, int y, int r, int g, int b) {
  46.    
  47.     float fr, fg, fb;
  48.    
  49.    
  50.     fr = (float) r / 255.0;
  51.     fg = (float) g / 255.0;
  52.     fb = (float) b / 255.0;
  53.    
  54.     glColor3f(fr, fg, fb);
  55.     glBegin(GL_POINTS);
  56.    
  57.     float xf = 0;
  58.     float yf = 0;
  59.    
  60.     if(x < 400){
  61.         xf = -0.999 + (float)x / 400;
  62.     }else{
  63.         xf = (float)x / 800;
  64.     }
  65.     if(y < 300){
  66.         yf = 0.999 - (float) y / 300;
  67.     }else{
  68.         yf = - (float) y / 600;
  69.     }
  70.    
  71.     if(x == 0){ xf = -0.99;}
  72.     if(y == 0){ yf = 0.99;}
  73.    
  74.     glVertex2f(xf, yf);  
  75.     glEnd();          
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement