Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <X11/X.h>
- #include <X11/Xlib.h>
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glx.h>
- #include "us_types.h"
- Display *displ;
- Window win;
- Window root;
- XEvent evn;
- GLint att[] = {GLX_RGBA,GLX_DEPTH_SIZE,24,GLX_DOUBLEBUFFER,None};
- XVisualInfo *vi;
- Colormap cmap;
- XSetWindowAttributes swa;
- GLXContext glc;
- XWindowAttributes gwa;
- GLuint texture1;
- u32 holst_x;
- u32 holst_y;
- u8* holst;
- u8 pereris = 1;
- GLvoid LoadHolst() {
- glGenTextures(1, &texture1);
- glBindTexture(GL_TEXTURE_2D, texture1);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D,0,3,400,400,0,GL_RGB,GL_UNSIGNED_BYTE,holst);
- }
- void DrawHolst() {
- printf("%i %i\n",holst_x,holst_y); //выводит 0 0 <---------------------------------------------------------- смотри сюда
- //glClearColor(0,0,0,0);
- //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- LoadHolst();
- glBegin(GL_QUADS);
- glTexCoord2f(0,1); glVertex2f(-1,1);
- glTexCoord2f(1,1); glVertex2f(1,1);
- glTexCoord2f(1,0); glVertex2f(1,-1);
- glTexCoord2f(0,0); glVertex2f(-1,-1);
- glEnd();
- }
- int main() {
- u32 holst_x = 400;
- u32 holst_y = 400;
- displ = (XOpenDisplay(NULL));
- root = DefaultRootWindow(displ);
- vi = glXChooseVisual(displ,0,att);
- cmap = XCreateColormap(displ,root,vi->visual,AllocNone);
- swa.colormap = cmap;
- swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | Button1MotionMask | Button2MotionMask;
- win = XCreateWindow(displ,root,0,0,holst_x,holst_y,0,vi->depth,InputOutput,vi->visual,CWColormap | CWEventMask,&swa);
- XMapWindow(displ,win);
- XStoreName(displ,win,"VERY SIMPLE APPLICATION");
- glc = glXCreateContext(displ,vi,NULL,GL_TRUE);
- glXMakeCurrent(displ,win,glc);
- holst = malloc(holst_x*holst_y*3);
- u64 i = 0;
- while (i < holst_x*holst_y*3) {
- *(holst + i) = 127;
- i++;
- }
- glEnable(GL_TEXTURE_2D);
- int cursor_x,cursor_y;
- while (1) {
- if (pereris) {
- XGetWindowAttributes(displ,win,&gwa);
- glViewport(0,0,gwa.width,gwa.height);
- printf("%i %i\n",holst_x,holst_y); //выводит 400 400 <------------------------------------- смотри сюда
- DrawHolst();
- glXSwapBuffers(displ,win);
- pereris = 0;
- }
- XNextEvent(displ,&evn);
- switch (evn.type) {
- case KeyPress: {
- glXMakeCurrent(displ,None,NULL);
- glXDestroyContext(displ,glc);
- XDestroyWindow(displ,win);
- XCloseDisplay(displ);
- free(holst);
- exit(0);
- break;
- }
- case ButtonPress: {
- cursor_x = evn.xbutton.x;
- cursor_y = evn.xbutton.y;
- switch (evn.xbutton.button) {
- case Button1: {
- *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3) = 255;
- *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3 + 1) = 255;
- *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3 + 2) = 0;
- break;
- }
- case Button3: {
- *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3) = 0;
- *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3 + 1) = 255;
- *(holst + ((holst_y - evn.xbutton.y - 1)*holst_x + evn.xbutton.x - 1)*3 + 2) = 255;
- break;
- }
- }
- pereris = 1;
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment