Guest User

Untitled

a guest
Apr 23rd, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <X11/X.h>
  4. #include <X11/Xlib.h>
  5. #include <GL/gl.h>
  6. #include <GL/glu.h>
  7. #include <GL/glx.h>
  8.  
  9. #include "us_types.h"
  10.  
  11. Display *displ;
  12. Window win;
  13. Window root;
  14. XEvent evn;
  15. GLint att[] = {GLX_RGBA,GLX_DEPTH_SIZE,24,GLX_DOUBLEBUFFER,None};
  16. XVisualInfo *vi;
  17. Colormap cmap;
  18. XSetWindowAttributes swa;
  19. GLXContext glc;
  20. XWindowAttributes gwa;
  21.  
  22. GLuint texture1;
  23.  
  24. u32 holst_x;
  25. u32 holst_y;
  26. u8* holst;
  27.  
  28. u8 pereris = 1;
  29.  
  30. GLvoid LoadHolst() {
  31.     glGenTextures(1, &texture1);
  32.     glBindTexture(GL_TEXTURE_2D, texture1);
  33.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
  34.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
  35.     glTexImage2D(GL_TEXTURE_2D,0,3,400,400,0,GL_RGB,GL_UNSIGNED_BYTE,holst);
  36. }
  37.  
  38. void DrawHolst() {
  39.     printf("%i %i\n",holst_x,holst_y); //выводит 0 0 <---------------------------------------------------------- смотри сюда
  40.     //glClearColor(0,0,0,0);
  41.     //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  42.    
  43.     LoadHolst();
  44.    
  45.     glBegin(GL_QUADS);
  46.     glTexCoord2f(0,1); glVertex2f(-1,1);
  47.     glTexCoord2f(1,1); glVertex2f(1,1);
  48.     glTexCoord2f(1,0); glVertex2f(1,-1);
  49.     glTexCoord2f(0,0); glVertex2f(-1,-1);
  50.     glEnd();
  51. }
  52.  
  53. int main() {
  54.     u32 holst_x = 400;
  55.     u32 holst_y = 400;
  56.    
  57.     displ = (XOpenDisplay(NULL));
  58.     root = DefaultRootWindow(displ);
  59.     vi = glXChooseVisual(displ,0,att);
  60.     cmap = XCreateColormap(displ,root,vi->visual,AllocNone);
  61.     swa.colormap = cmap;
  62.     swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | Button1MotionMask | Button2MotionMask;
  63.     win = XCreateWindow(displ,root,0,0,holst_x,holst_y,0,vi->depth,InputOutput,vi->visual,CWColormap | CWEventMask,&swa);
  64.     XMapWindow(displ,win);
  65.     XStoreName(displ,win,"VERY SIMPLE APPLICATION");
  66.     glc = glXCreateContext(displ,vi,NULL,GL_TRUE);
  67.     glXMakeCurrent(displ,win,glc);
  68.    
  69.     holst = malloc(holst_x*holst_y*3);
  70.    
  71.     u64 i = 0;
  72.     while (i < holst_x*holst_y*3) {
  73.         *(holst + i) = 127;
  74.         i++;
  75.     }
  76.    
  77.     glEnable(GL_TEXTURE_2D);
  78.    
  79.     int cursor_x,cursor_y;
  80.    
  81.     while (1) {
  82.         if (pereris) {
  83.             XGetWindowAttributes(displ,win,&gwa);
  84.             glViewport(0,0,gwa.width,gwa.height);
  85.             printf("%i %i\n",holst_x,holst_y); //выводит 400 400 <------------------------------------- смотри сюда
  86.             DrawHolst();
  87.             glXSwapBuffers(displ,win);
  88.             pereris = 0;
  89.         }
  90.        
  91.         XNextEvent(displ,&evn);
  92.        
  93.         switch (evn.type) {
  94.             case KeyPress: {
  95.                 glXMakeCurrent(displ,None,NULL);
  96.                 glXDestroyContext(displ,glc);
  97.                 XDestroyWindow(displ,win);
  98.                 XCloseDisplay(displ);
  99.                 free(holst);
  100.                 exit(0);
  101.                 break;
  102.             }
  103.             case ButtonPress: {
  104.                 cursor_x = evn.xbutton.x;
  105.                 cursor_y = evn.xbutton.y;
  106.                 switch (evn.xbutton.button) {
  107.                     case Button1: {
  108.                         *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3) = 255;
  109.                         *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3 + 1) = 255;
  110.                         *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3 + 2) = 0;
  111.                         break;
  112.                     }
  113.                     case Button3: {
  114.                         *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3) = 0;
  115.                         *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3 + 1) = 255;
  116.                         *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3 + 2) = 255;
  117.                         break;
  118.                     }
  119.                 }
  120.                 pereris = 1;
  121.                 break;
  122.             }
  123.            
  124.            
  125.            
  126.            
  127.            
  128.         }
  129.     }
  130. }
Add Comment
Please, Sign In to add comment