• vivichrist

    so yeah, done. The answer to the puzzle was glXGetCurrentDisplay().

    posted in Kode read more
  • vivichrist

    do you mind if I use GLX calls?
    that is between:

    #ifdef KORE_OPENGL
    ...
    #endif

    posted in Kode read more
  • vivichrist

    that is bazaar There must be some subtle difference that I will have to find. It's one of those unreported errors because "The show must go on!" type deals.

    posted in Kode read more
  • vivichrist

    It works in my demo program X11Test but not when used in the Kore Mouse.cpp file. The Linux specific file, that is.

    posted in Kode read more
  • vivichrist

    actually, after much tinkering I got the original code to work so it must be something else 😞

    posted in Kode read more
  • vivichrist

    Ok so I modified my small program to give something like the desired behaviour:
    Drop Box link to X11Test Code Blocks project
    Can you confirm?

    posted in Kode read more
  • vivichrist

    perhaps adding the LeaveNotifyMask to

    swa.event_mask = KeyPressMask | KeyReleaseMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask;
    

    and adding it to the event handling?

    posted in Kode read more
  • vivichrist

    bool Kore::System::handleMessages(); ?

    posted in Kode read more
  • vivichrist

    There is: "the X server reports EnterNotify or LeaveNotify events to clients who have selected for these events" if I can find where to receive this notification (I suspect Backends/System/Linux/.../System.cpp) then I can call show(true) and problem solved.

    posted in Kode read more
  • vivichrist

    Where do I find the Leave() in:

    void Mouse::___leave(int windowId) {
    	if (Leave != nullptr) {
    		Leave(windowId);
    	}
    }
    

    is that in the X11 API?

    posted in Kode read more
  • vivichrist

    oh and instancing with instPos and instTint.

    posted in Kode read more
  • vivichrist

    Um oops sorry false alarm, I just missed the terminal text telling me about all the spir-v conversion errors because of vscode's popup directing me towards the Problems tab. Geometry shaders seem to compile ok but I have yet to test it. This the shader I intend to use. It just adds edges to triangles using barycentric coordinates:

    #version 450
    
    // Input vertex data, different for all executions of this shader
    in vec3 pos;
    in vec2 uv;
    in vec3 nor;
    in vec3 instPos;
    in vec3 instTint;
    
    // Output data: will be interpolated for each fragment
    out vec2 vUV;
    out vec3 vView;
    out vec3 vNormal;
    out vec3 vEyeDir;
    out vec3 vLightDir;
    
    // Values that stay constant for the whole mesh
    uniform mat4 VP;
    uniform mat4 V;
    uniform mat4 M;
    uniform vec3 lightPos;
    
    void main() {
    	// Output position of the vertex, in clip space: MVP * position
    	gl_Position = VP * M * vec4(pos + instPos, 1.0);
    	// Position of the vertex, in world coordinates : M * position
    	vView = (M * vec4(pos + instPos, 1.0)).xyz;
    	// Vector that goes from the vertex to the camera, in camera space.
    	// In camera space, the camera is at the origin (0,0,0).
    	vec3 cameraSpace = (V * M * vec4(pos + instPos, 1.0)).xyz;
    	vEyeDir = vec3(0.0, 0.0, 0.0) - cameraSpace;
    	// Vector that goes from the vertex to the light,
    	// in camera space. M is ommited because it's identity.
    	vec3 lightPosCamSpace = (V * vec4(lightPos, 1.0)).xyz;
    	vLightDir = lightPosCamSpace + vEyeDir;
    	// Normal of the the vertex, in camera space
    	// Only correct if modelMatrix does not scale the model! Use its inverse transpose if not.
    	vNormal = (V * M * vec4(nor, 0.0)).xyz;
    	// UV of the vertex. No special space for this one.
    	vUV = uv;
    }
    
    #version 450
    layout(triangles) in;
    layout(triangle_strip, max_vertices = 3) out;
    
    in vec2 vUV[];
    in vec3 vView[];
    in vec3 vNormal[];
    in vec3 vEyeDir[];
    in vec3 vLightDir[];
    
    out vec2 texcoords;
    out vec3 worldspace;
    out vec3 normCamSpace;
    out vec3 eyeDirCamSpace;
    out vec3 lightDirCamSpace;
    noperspective out vec3 dists;
    
    void main()
    {
    	vec3 d;
    	// Barcentric coordinates.
    	d.x = length(cross(gl_in[0].gl_Position.xyz - gl_in[1].gl_Position.xyz,
    					   gl_in[0].gl_Position.xyz - gl_in[2].gl_Position.xyz))
    					 / length(gl_in[2].gl_Position.xyz - gl_in[1].gl_Position.xyz);
    	d.y = length(cross(gl_in[1].gl_Position.xyz - gl_in[0].gl_Position.xyz,
    					   gl_in[1].gl_Position.xyz - gl_in[2].gl_Position.xyz))
    					 / length(gl_in[2].gl_Position.xyz - gl_in[0].gl_Position.xyz);
    	d.z = length(cross(gl_in[2].gl_Position.xyz - gl_in[1].gl_Position.xyz,
    					   gl_in[2].gl_Position.xyz - gl_in[0].gl_Position.xyz))
    					 / length(gl_in[0].gl_Position.xyz - gl_in[1].gl_Position.xyz);
    	for(int i = 0; i < 3; ++i)
    	{
    		dists = vec3(0);
    		dists[i] = d[i];
    		texcoords = vUV[i];
    		normCamSpace = vNormal[i];
    		worldspace = vView[i];
    		lightDirCamSpace = vLightDir[i];
    		gl_Position = gl_in[i].gl_Position;
    		EmitVertex();
    	}
    	EndPrimitive();
    }
    
    #version 450
    
    // Interpolated values from the vertex shaders
    in vec2 texcoords;
    in vec3 worldspace;
    in vec3 normCamSpace;
    in vec3 eyeDirCamSpace;
    in vec3 lightDirCamSpace;
    noperspective in vec3 dists;
    
    // Values that stay constant for the whole mesh.
    uniform sampler2D diffTex;
    uniform vec3 lightPos;
    
    out vec4 fragColor;
    
    void main() {
    
    	// Light emission properties
    	// You probably want to put them as uniforms
    	vec3 lightColor = vec3(1.0,1.0,1.0);
    	float lightPower = 50.0;
    	
    	// Material properties
    	vec3 materialDiffuseColor = texture(diffTex, texcoords).rgb;
    	vec3 materialAmbientColor = vec3(0.1, 0.1, 0.1) * materialDiffuseColor;
    	vec3 materialSpecularColor = vec3(0.3, 0.3, 0.3);
    
    	// Distance to the light
    	float distance = length(lightPos - worldspace);
    
    	// Normal of the computed fragment, in camera space
    	vec3 n = normalize(normCamSpace);
    	// Direction of the light (from the fragment to the light)
    	vec3 l = normalize(lightDirCamSpace);
    	// Cosine of the angle between the normal and the light direction, 
    	// clamped above 0
    	//  - light is at the vertical of the triangle -> 1
    	//  - light is perpendicular to the triangle -> 0
    	//  - light is behind the triangle -> 0
    	float cosTheta = clamp(dot(n, l), 0.0, 1.0);
    	
    	// Eye vector (towards the camera)
    	vec3 E = normalize(eyeDirCamSpace);
    	// Direction in which the triangle reflects the light
    	vec3 R = (-l) - 2.0 * dot(n, (-l)) * n;
    	//vec3 R = reflect(-l,n); // TODO: waiting for krafix fix
    
    	// Cosine of the angle between the Eye vector and the Reflect vector,
    	// clamped to 0
    	//  - Looking into the reflection -> 1
    	//  - Looking elsewhere -> < 1
    	float cosAlpha = clamp(dot(E, R), 0.0, 1.0);
    
    	// Multiply intensity by diffuse color, force alpha to 1.0 and add in ambient light
    	float d = min(min( dists.x, dists.y), dists.z );
    	float frameMix = exp2(0.25+(-1500)*(1 - gl_FragCoord.z)*d*d);
    	materialDiffuseColor = mix( materialDiffuseColor, vec3( 1,0,0 ), frameMix );
    	
    	fragColor = vec4(vec3(
    		// Ambient: simulates indirect lighting
    		materialAmbientColor +
    		// Diffuse: "color" of the object
    		materialDiffuseColor * lightColor * lightPower * cosTheta / (distance * distance) +
    		// Specular: reflective highlight, like a mirror
    		materialSpecularColor * lightColor * lightPower * pow(cosAlpha, 5.0) / (distance * distance)
    	), 1.0);
    }
    

    posted in Kode read more
  • vivichrist

    I got an error from trying to compile some shaders in "Sources/Shaders/*". Does this mean I can't use geometry shaders or have I got the syntax wrong in those shaders?

    Using Kha from /mnt/kreotem/Deps/lib/Kha/git
    Creating Kha project.
    Compiling shader 1 of 7 (phong.frag.glsl).
    Compiling shader 2 of 7 (phong.vert.glsl).
    Compiling shader 3 of 7 (phong2.frag.glsl).
    Compiling shader 4 of 7 (phong2.geom.glsl).
    Compiling shader 5 of 7 (phong2.vert.glsl).
    Compiling shader 6 of 7 (simple.frag.glsl).
    Compiling shader 7 of 7 (simple.vert.glsl).
    Compiling shader 1 of 8 (painter-colored.frag.glsl).
    Compiling shader 2 of 8 (painter-colored.vert.glsl).
    Compiling shader 3 of 8 (painter-image.frag.glsl).
    Compiling shader 4 of 8 (painter-image.vert.glsl).
    Compiling shader 5 of 8 (painter-text.frag.glsl).
    Compiling shader 6 of 8 (painter-text.vert.glsl).
    Compiling shader 7 of 8 (painter-video.frag.glsl).
    Compiling shader 8 of 8 (painter-video.vert.glsl).
    /mnt/kreotem/Deps/lib/Kha/git/Sources/kha/internal/ShadersBuilder.hx:84: characters 59-64 : Array<kha.Blob> should be kha.Blob
    ${haxelibPath}/Kha/git/Sources/kha/internal/ShadersBuilder.hx:84: characters 59-64 : Array<kha.Blob> should be kha.internal.BytesBlob
    ${haxelibPath}/Kha/git/Sources/kha/internal/ShadersBuilder.hx:84: characters 59-64 : For function argument 'source'
    ${haxelibPath}/Kha/git/Sources/kha/Shaders.hx:4: lines 4-6 : Defined in this class

    posted in Kode read more
  • vivichrist

    have created a pull request and is doing lots of Windows tests lol

    posted in Kode read more
  • vivichrist

    So, I guess I can't just push to a new branch because I don't have permission. Also the effect of hiding the mouse this way is for the whole screen and not just the window. Is that desired behaviour?

    posted in Kode read more
  • vivichrist

    However the following code works with g++ arguments of -lX11 -lXfixes. Possibly extraneous includes. There you go 🙂

    #include <iostream>
    #include <X11/X.h>
    #include <X11/Xlib.h>
    #include <X11/keysym.h>
    #include <X11/Xutil.h>
    #include <X11/extensions/Xfixes.h>
    #include <string>
    #include <iostream>
    
    Window window;
    void show(Display *dpy);
    
    int main()
    {
        Display *display;
        XEvent e;
        std::string msg = "Hello, World!";
        int screen;
    
        display = XOpenDisplay(nullptr);
        if (display == nullptr)
        {
            std::cerr << "Cannot open display\n";
            throw;
        }
    
        screen = XDefaultScreen(display);
        window = XCreateSimpleWindow(display, RootWindow(display, screen), 10, 10, 500, 500, 1,
                                     BlackPixel(display, screen), WhitePixel(display, screen));
        XStoreName(display, window, "Silly Window");
        XSelectInput(display, window, ExposureMask | KeyPressMask );
        XMapWindow(display, window);
    
        while (true)
        {
            XNextEvent(display, &e);
            if (e.type == Expose)
            {
                std::cout << "Window Exposed!\n";
                XExposeEvent ev = e.xexpose;
                if (ev.window != window) continue;
                XFillRectangle(display, window, DefaultGC(display, screen), 50, 50, 400, 50);
                XDrawString(display, window, DefaultGC(display, screen), 220, 150, msg.c_str(), msg.length());
                XDrawString(display, window, DefaultGC(display, screen), 220, 220, msg.c_str(), msg.length());
                XDrawString(display, window, DefaultGC(display, screen), 220, 300, msg.c_str(), msg.length());
                XFillRectangle(display, window, DefaultGC(display, screen), 50, 400, 400, 50);
            }
            else if (e.type == KeyPress)
            {
                char buf[128] = {0};
                KeySym keysym;
                int len = XLookupString(&e.xkey, buf, sizeof buf, &keysym, NULL);
                if (keysym == XK_Escape)
                {
                    break;
                }
                else if (keysym == XK_space)
                {
                    show(display);
                    XAllowEvents(display, SyncBoth, CurrentTime);
                }
            }
    
        }
    
        XDestroyWindow(display, window);
        XCloseDisplay(display);
        return 0;
    }
    
    bool toggle = true;
    void show(Display *dpy)
    {
        if (toggle)
        {
            std::cout << "toggle On->Off\n";
            XFixesHideCursor(dpy, DefaultRootWindow(dpy));
            XFlush(dpy);
        }
        else
        {
            std::cout << "toggle Off->On\n";
            XFixesShowCursor(dpy, DefaultRootWindow(dpy));
            XFlush(dpy);
        }
        toggle = !toggle;
    }
    

    posted in Kode read more
  • vivichrist

    Ok so what I found out is that this should be the way to do mouse hiding currently. Will test it 🙂

    #include <X11/Xlib.h>
    #include <X11/extensions/XInput2.h>
    #include <X11/extensions/Xfixes.h>
    ...
    bool hidden = false;
    
    void cursor_show(void) {
        if (!hidden)
            return;
    
        //Showing the cursor
        XFixesShowCursor(display, DefaultRootWindow(display));
        XFlush(display);
        hidden = false;
    }
    
    void cursor_hide(void) {
        if (hidden)
            return;
    
        //"Hiding the cursor
        XFixesHideCursor(display, DefaultRootWindow(display));
        XFlush(display);
        hidden = true;
    }
    

    posted in Kode read more
  • vivichrist

    I tried a few different things but mouse cursor under Gnome is flakey as. I remember there was a space of about a couple of years where changing you mouse cursor in Debian based distros was not possible without writing it to /user/share/...something (required admin privileges). X11 is a mess of bung.

    posted in Kode read more
  • vivichrist

    Doesn't hide the mouse cursor when compiling to native code i.e the "Kha: Build for Linux". I am currently trying to work with this code and see if it can work. Also debugging this will be a bit easier than having to deal with all of the generated HaXe C++.

    #include <iostream>
    #include <X11/X.h>
    #include <X11/Xlib.h>
    #include <X11/keysym.h>
    #include <X11/Xutil.h>
    #include <X11/Xos.h>
    
    #include <string>
    #include <iostream>
    
    Window window;
    void show();
    
    int main()
    {
        Display *display;
        XEvent e;
        std::string msg = "Hello, World!";
        int screen;
    
        display = XOpenDisplay(nullptr);
        if (display == nullptr)
        {
            std::cerr << "Cannot open display\n";
            throw;
        }
    
        screen = XDefaultScreen(display);
        window = XCreateSimpleWindow(display, RootWindow(display, screen), 10, 10, 500, 500, 1,
                                     BlackPixel(display, screen), WhitePixel(display, screen));
        XStoreName(display, window, "Silly Window");
        XSelectInput(display, window, ExposureMask | KeyPressMask );
        XMapWindow(display, window);
    
        while (true)
        {
            XNextEvent(display, &e);
            if (e.type == Expose)
            {
                std::cout << "Window Exposed!\n";
                XExposeEvent ev = e.xexpose;
                if (ev.window != window) continue;
                XFillRectangle(display, window, DefaultGC(display, screen), 50, 50, 400, 50);
                XDrawString(display, window, DefaultGC(display, screen), 220, 220, msg.c_str(), msg.length());
                XFillRectangle(display, window, DefaultGC(display, screen), 50, 400, 400, 50);
            }
            else if (e.type == KeyPress)
            {
                char buf[128] = {0};
                KeySym keysym;
                int len = XLookupString(&e.xkey, buf, sizeof buf, &keysym, NULL);
                if (keysym == XK_Escape)
                {
                    break;
                }
                else if (keysym == XK_space)
                {
                    show();
                    XAllowEvents(display, SyncBoth, CurrentTime);
                }
            }
    
        }
    
        XDestroyWindow(display, window);
        XCloseDisplay(display);
        return 0;
    }
    
    bool toggle = false;
    void show()
    {
        Display* dpy = XOpenDisplay(0);
        if (toggle)
        {
            std::cout << "toggle On\n";
            XUndefineCursor(dpy, window);
        }
        else
        {
            std::cout << "toggle Off\n";
            XColor col;
            char data[1] = {0X00};
            Pixmap blank = XCreateBitmapFromData(dpy, window, data, 1, 1);
            Cursor cursor = XCreatePixmapCursor(dpy, blank, blank, &col, &col, 0, 0);
            XDefineCursor(dpy, window, cursor);
            XSetWindowAttributes wa;
            XChangeWindowAttributes(dpy, window, CWCursor, &wa);
            wa.cursor = cursor;
            XFreePixmap(dpy, blank);
        }
        toggle = !toggle;
    }
    

    Note: Updated code

    posted in Kode read more
  • vivichrist

    Stepping through the code with the debugger there are no exceptions or errors thrown or reported. It looks ok, it follows logically, that is, its just creating a blank cursor to replace the system defined one, though nothing in the docs says anything about the dimensions of the cursor. I looked at the docs for X11 and this would be the way to do it. I need to learn more about how to compile haxe/Kha. But the reason I am hating on C++ so much is that I did a third year paper where we (the students) were expected to learn C++ and OpenGL/GLSL then create a rendering pipeline. that was a lot of work to get... Parallax Occlusion Mapping, Ambient Occlusion, Bloom and Depth of Field all happening between us (a group of three). Most of the others were sticking with OpenGL 2.0 where as I decided to go with 3.3 (which, at the time Intel had just updated their drivers on linux). My experience of C++ is one of flakey brittle code that is very hard to think or reason about, so many corner cases, exceptions and weird limits etc. (same with C in my opinion) I like Kha for it's concise simplicity and nicely defined abstraction that still appeals to my understanding of OpenGL and shaders but without all the crazy house keeping and menial tasks. The design of the API is just what I was looking for in a graphics engine. I much more like to just program shaders. Also I would be quite interested in developing a shader language of my own.
    But having said all this I will try to make a small program that tests the above code snippet as a kind of unit test.

    posted in Kode read more

Looks like your connection to Kode Forum was lost, please wait while we try to reconnect.