Code Monkey home page Code Monkey logo

kms-glsl's People

Contributors

astefanutti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

kms-glsl's Issues

Broken on a Pi Zero 2 W and Pi 3

Tested with latest Raspberry Pi OS Bullseye 64 bit and last version of pi Os Buster 64 bit.

image

kmscube app runs with no problems

Great work

Sorry for using this issues section to comment on the fantastic job you have done putting this together. Good stuff!

I would love to be able to control shaders through an ADC on the raspberry pi. Is there some way to launch a shader file from the cli using python and have python read an ADC (like the mcp3008) and pass this on to a shader so that for example you can use an external knob to control a colour in the shader code? This project has great potential to be turned into a cool module that can act as a backdrop for (electronic) musicians. See my website also: www.erikoostveen.co.uk

How do I open in windowed mode?

Hello,

awesome test under Ubuntu 22.04 but I cannot press Ctrl+c because it happens fullscreen. Wow! nice effects but I cannot return and I try to reboot.

But I don't understand because xcb has xcb_randar...

Thanks!

Pi Zero 2 W TV out setup

Outputting to composite out.
dtoverlay=vc4-fkms-v3d

kmscube works but I just get a similar output with most examples.
image

[Feature Request] Run on Orange pi PC2?

Is this possible?
I have a raspi also, on that it runs perfectly.

But here when I start glsl, the image is just blinking black-white, and console tells me Connection attempt to X server failed with error 5, falling back to DRM

Glxgeras works fine.

orangepi@orangepipc2:~/kms-glsl$ uname -a
Linux orangepipc2 5.4.65-sunxi64 #2.1.2 SMP Tue Mar 30 18:13:54 CST 2021 aarch64 aarch64 aarch64 GNU/Linux

Full output:

orangepi@orangepipc2:~/kms-glsl$ ./glsl examples/surveillance_mosaic.glsl 
Connection attempt to X server failed with error 5, falling back to DRM
Using display 0xaaaae2e35130 with EGL version 1.4
===================================
EGL information:
  version: "1.4"
  vendor: "Mesa Project"
===================================
OpenGL ES 2.x information:
  version: "OpenGL ES 2.0 Mesa 20.0.8"
  shading language version: "OpenGL ES GLSL ES 1.0.16"
  vendor: "lima"
  renderer: "Mali450"
===================================
Using GLSL version directive: #version 100
Rendered 120 frames in 2.014050 sec (59.581441 fps)
Rendered 240 frames in 4.028177 sec (59.580306 fps)

MAKE log:

orangepi@orangepipc2:~/kms-glsl$ make
gcc -c -g -Wall -O3 -Winvalid-pch -Wextra -std=gnu99 -fPIC -fdiagnostics-color=always -pipe -pthread -I/usr/include/libdrm common.c -o common.o
gcc -c -g -Wall -O3 -Winvalid-pch -Wextra -std=gnu99 -fPIC -fdiagnostics-color=always -pipe -pthread -I/usr/include/libdrm drm-atomic.c -o drm-atomic.o
drm-atomic.c: In function ‘on_pageflip_event’:
drm-atomic.c:147:7: warning: unused parameter ‘fd’ [-Wunused-parameter]
   int fd,
       ^~
drm-atomic.c:148:16: warning: unused parameter ‘frame’ [-Wunused-parameter]
   unsigned int frame,
                ^~~~~
drm-atomic.c:149:16: warning: unused parameter ‘sec’ [-Wunused-parameter]
   unsigned int sec,
                ^~~
drm-atomic.c:150:16: warning: unused parameter ‘usec’ [-Wunused-parameter]
   unsigned int usec,
                ^~~~
drm-atomic.c:151:9: warning: unused parameter ‘userdata’ [-Wunused-parameter]
   void *userdata
         ^~~~~~~~
gcc -c -g -Wall -O3 -Winvalid-pch -Wextra -std=gnu99 -fPIC -fdiagnostics-color=always -pipe -pthread -I/usr/include/libdrm drm-common.c -o drm-common.o
gcc -c -g -Wall -O3 -Winvalid-pch -Wextra -std=gnu99 -fPIC -fdiagnostics-color=always -pipe -pthread -I/usr/include/libdrm drm-legacy.c -o drm-legacy.o
gcc -c -g -Wall -O3 -Winvalid-pch -Wextra -std=gnu99 -fPIC -fdiagnostics-color=always -pipe -pthread -I/usr/include/libdrm glsl.c -o glsl.o
glsl.c: In function ‘init’:
glsl.c:146:28: warning: passing argument 2 of ‘init_shadertoy’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  ret = init_shadertoy(gbm, egl, shadertoy);
                            ^~~
In file included from glsl.c:33:0:
common.h:180:5: note: expected ‘struct egl *’ but argument is of type ‘const struct egl *’
 int init_shadertoy(const struct gbm *gbm, struct egl *egl, const char *shadertoy);
     ^~~~~~~~~~~~~~
glsl.c: In function ‘thread_run’:
glsl.c:251:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  return (void *) drm->run(gbm, egl);
         ^
gcc -c -g -Wall -O3 -Winvalid-pch -Wextra -std=gnu99 -fPIC -fdiagnostics-color=always -pipe -pthread -I/usr/include/libdrm lease.c -o lease.o
gcc -c -g -Wall -O3 -Winvalid-pch -Wextra -std=gnu99 -fPIC -fdiagnostics-color=always -pipe -pthread -I/usr/include/libdrm perfcntrs.c -o perfcntrs.o
gcc -c -g -Wall -O3 -Winvalid-pch -Wextra -std=gnu99 -fPIC -fdiagnostics-color=always -pipe -pthread -I/usr/include/libdrm shadertoy.c -o shadertoy.o
shadertoy.c: In function ‘init_shadertoy’:
shadertoy.c:262:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
   asprintf(&version_directive, "#version %s", version);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
shadertoy.c:266:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
   asprintf(&shadertoy_vs, is_glsl_3 ? shadertoy_vs_tmpl_300 : shadertoy_vs_tmpl_100, version_directive);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
shadertoy.c:267:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
   asprintf(&shadertoy_fs, is_glsl_3 ? shadertoy_fs_tmpl_300 : shadertoy_fs_tmpl_100, version_directive, shader);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
shadertoy.c:269:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
   asprintf(&shadertoy_vs, shadertoy_vs_tmpl_100, version);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
shadertoy.c:270:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
   asprintf(&shadertoy_fs, shadertoy_fs_tmpl_100, version, shader);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
shadertoy.c: In function ‘glsl_version’:
shadertoy.c:185:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
   asprintf(&version, "%s%s%s", major, minor, hasES ? " es" : "");
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc -Wl,--no-as-needed -lGLESv2 -Wl,--as-needed,--no-undefined common.o drm-atomic.o drm-common.o drm-legacy.o glsl.o lease.o perfcntrs.o shadertoy.o -lGLESv2 -lEGL -ldrm -lgbm -lxcb-randr -lxcb -lpthread -o glsl
gcc -Wl,--no-as-needed -lGLESv2 -Wl,--as-needed,--no-undefined common.o drm-atomic.o drm-common.o drm-legacy.o glsl.o lease.o perfcntrs.o shadertoy.o -lGLESv2 -lEGL -ldrm -lgbm -lxcb-randr -lxcb -lpthread -shared -o glsl.so

Thanks!

failed to set mode : Permission denied

Hello, i tried to run the program on a raspberry pi 3B+ using raspi os ver 4.2 .

Compilation worked fine bit when i try to run an example shader, get the following error:
"failed to set mode : Permission denied"

I did the required changes to the /boot/config.txt, have the following dependencies versions :
gcc 4:10.2.1-1+rpi1
make 4.3-4.1
libdrm-dev 2.4.104-1+rpi1
libgbm-dev 20.3.5-1+rpt4+rpi1
libegl-dev 1.3.2-1
libgles2-mesa-dev 20.3.5-1+rpt4+rpi1

Uname -a command returns the following output :
Linux raspberrypi 5.15.32-v7+ #1538 SMP armv7l

I tried to enable experimental wayland backend support, activated gl full kms desktop driver support and the same error remains.
I noticed while i launched the command that i have the following parameters:

OpenGL ES 2.x information:

version: "OpenGL ES 2.0 Mesa 20.3.5"

shading language version: "OpenGL ES GLSL ES 1.0.16"

vendor: "Broadcom"

renderer: "VC4 V3D 2.1"

Any ideas? Thanks in advance

Composite video on Pi4?

Sorry if this is a naive question, but I get the error “failed to initialize legacy DRM” when I try running the program through composite. I can get the program to run on HDMI with the modifier “-d /dev/dri/card1” and without, it returns “unable to get DRM resources”. Enabling/disabling vc4-kms-v3d also doesn’t change anything for composite. I’m guessing there is some difference in how the composite video is processed that makes this impossible because I can’t find a program that can do that on Pi4. the goal is to make a shader player that I can manipulate for live visuals and use in an analog setup.

Thanks for your contributions to make OpenGL more usable for the Pi :)

switching the output to the second hdmi port?

Hello,

I am using two displays, each connected to an HDMI port from my RPI CM4. But the program is only displayed on HDMI port 0. Is it possible to show the output on the second HDMI port? What do I have to change in the code for this or is it possible at all?

A little patch for shadertoy.c that allows for variables sent through a socket

Since I saw that some other people also wanted to be able to pass in variables into a shader, I hacked this patch together (with the help of GPT-4) which adds four uniforms vec4 iAux0, iAux1, iAux2 and iAux3 to the shader code and which can be updated by sending new values via a socket connection (e.g. from a Python script). Since this alters the functionality I did not want to submit this as a pull request, so please the excuse the bloatedness of this post.

It is all very rough and basic, but maybe someone with better C skills than me can turn this into something more universal. Of course you can also alter the variable names or types depending on your needs.

In Makefile you will have to add -lpthread to the libs since the socket runs in a thread, so the line has to be changed to this
LDLIBS=-lGLESv2 -lEGL -ldrm -lgbm -lxcb-randr -lxcb -lpthread

Patched shadertoy.c

/*
 * Copyright © 2020 Antonin Stefanutti <[email protected]>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sub license,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#define _GNU_SOURCE

#include <err.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <regex.h>
#include <stdlib.h>

#include <GLES3/gl3.h>

#include "common.h"


/*
* Socket Server Code start
*/

#include <pthread.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>

volatile float vec0[] = {0.0f, 0.0f, 0.0f, 0.0f};
volatile float vec1[] = {0.0f, 0.0f, 0.0f, 0.0f};
volatile float vec2[] = {0.0f, 0.0f, 0.0f, 0.0f};
volatile float vec3[] = {0.0f, 0.0f, 0.0f, 0.0f};
volatile int updated = 0;

void* socketServer() {
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    struct sockaddr_in server_addr;
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(1234);
    server_addr.sin_addr.s_addr = INADDR_ANY;
    bind(sockfd, (struct sockaddr*) &server_addr, sizeof(server_addr));
    listen(sockfd, 5);

    while(1) {
        int new_sock;
        struct sockaddr_in client_addr;
        socklen_t addr_size = sizeof(client_addr);
        char buffer[1024] = {0};
        printf("\nListening for incoming connections...\n");
        new_sock = accept(sockfd, (struct sockaddr*) &client_addr, &addr_size);

        while(1) {
            memset(buffer, 0, sizeof(buffer));
            int nbytes = read(new_sock, buffer, sizeof(buffer));
            if(nbytes <= -1) { // -1 is returned by read() if there's an error
                perror("read error or connection closed by client");
                break;
            }
            
            sscanf(buffer, "%f,%f,%f,%f %f,%f,%f,%f %f,%f,%f,%f  %f,%f,%f,%f",
                   &vec0[0], &vec0[1], &vec0[2], &vec0[3],
                   &vec1[0], &vec1[1], &vec1[2], &vec1[3],
                   &vec2[0], &vec2[1], &vec2[2], &vec2[3],
                   &vec3[0], &vec3[1], &vec3[2], &vec3[3]);

            updated = 1;
        }
        close(new_sock);
    }
    return NULL;
}


/*
* Socket Server Code end
*/



GLint iTime, iFrame, iAux0, iAux1, iAux2, iAux3;

static const char *shadertoy_vs_tmpl_100 =
		"// version (default: 1.10)              \n"
		"%s                                      \n"
		"                                        \n"
		"attribute vec3 position;                \n"
		"                                        \n"
		"void main()                             \n"
		"{                                       \n"
		"    gl_Position = vec4(position, 1.0);  \n"
		"}                                       \n";

static const char *shadertoy_vs_tmpl_300 =
		"// version                              \n"
		"%s                                      \n"
		"                                        \n"
		"in vec3 position;                       \n"
		"                                        \n"
		"void main()                             \n"
		"{                                       \n"
		"    gl_Position = vec4(position, 1.0);  \n"
		"}                                       \n";

static const char *shadertoy_fs_tmpl_100 =
		"// version (default: 1.10)                                                           \n"
		"%s                                                                                   \n"
		"                                                                                     \n"
		"#ifdef GL_FRAGMENT_PRECISION_HIGH                                                    \n"
		"precision highp float;                                                               \n"
		"#else                                                                                \n"
		"precision mediump float;                                                             \n"
		"#endif                                                                               \n"
		"                                                                                     \n"
		"uniform vec3      iResolution;           // viewport resolution (in pixels)          \n"
		"uniform float     iTime;                 // shader playback time (in seconds)        \n"
		"uniform int       iFrame;                // current frame number                     \n"
		"uniform vec4      iMouse;                // mouse pixel coords                       \n"
		"uniform vec4      iDate;                 // (year, month, day, time in seconds)      \n"
		"uniform float     iSampleRate;           // sound sample rate (i.e., 44100)          \n"
		"uniform vec3      iChannelResolution[4]; // channel resolution (in pixels)           \n"
		"uniform float     iChannelTime[4];       // channel playback time (in sec)           \n"
		"uniform vec4      iAux0;                 // Auxillary value from socket              \n"
		"uniform vec4      iAux1;                 // Auxillary value from socket              \n"
		"uniform vec4      iAux2;                 // Auxillary value from socket              \n"
		"uniform vec4      iAux3;                 // Auxillary value from socket              \n"
		"                                                                                     \n"
		"// Shader body                                                                       \n"
		"%s                                                                                   \n"
		"                                                                                     \n"
		"void main()                                                                          \n"
		"{                                                                                    \n"
		"    mainImage(gl_FragColor, gl_FragCoord.xy);                                        \n"
		"}                                                                                    \n";

static const char *shadertoy_fs_tmpl_300 =
		"// version                                                                           \n"
		"%s                                                                                   \n"
		"                                                                                     \n"
		"#ifdef GL_FRAGMENT_PRECISION_HIGH                                                    \n"
		"precision highp float;                                                               \n"
		"#else                                                                                \n"
		"precision mediump float;                                                             \n"
		"#endif                                                                               \n"
		"                                                                                     \n"
		"out vec4 fragColor;                                                                  \n"
		"                                                                                     \n"
		"uniform vec3      iResolution;           // viewport resolution (in pixels)          \n"
		"uniform float     iTime;                 // shader playback time (in seconds)        \n"
		"uniform int       iFrame;                // current frame number                     \n"
		"uniform vec4      iMouse;                // mouse pixel coords                       \n"
		"uniform vec4      iDate;                 // (year, month, day, time in seconds)      \n"
		"uniform float     iSampleRate;           // sound sample rate (i.e., 44100)          \n"
		"uniform vec3      iChannelResolution[4]; // channel resolution (in pixels)           \n"
		"uniform float     iChannelTime[4];       // channel playback time (in sec)           \n"
		"uniform vec4      iAux0;                 // Auxillary value from socket              \n"
		"uniform vec4      iAux1;                 // Auxillary value from socket              \n"
		"uniform vec4      iAux2;                 // Auxillary value from socket              \n"
		"uniform vec4      iAux3;                 // Auxillary value from socket              \n"
		"                                                                                     \n"
		"// Shader body                                                                       \n"
		"%s                                                                                   \n"
		"                                                                                     \n"
		"void main()                                                                          \n"
		"{                                                                                    \n"
		"    mainImage(fragColor, gl_FragCoord.xy);                                           \n"
		"}                                                                                    \n";

static const GLfloat vertices[] = {
		// First triangle:
		1.0f, 1.0f,
		-1.0f, 1.0f,
		-1.0f, -1.0f,
		// Second triangle:
		-1.0f, -1.0f,
		1.0f, -1.0f,
		1.0f, 1.0f,
};

static const char *load_shader(const char *file) {
	struct stat statbuf;
	int fd, ret;

	fd = open(file, 0);
	if (fd < 0) {
		err(fd, "could not open '%s'", file);
	}

	ret = fstat(fd, &statbuf);
	if (ret < 0) {
		err(ret, "could not stat '%s'", file);
	}

	return mmap(NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
}

#define GLSL_VERSION_REGEX "GLSL[[:space:]]*(ES)?[[:space:]]*([[:digit:]]+)\\.([[:digit:]]+)"

static char *extract_group(const char *str, regmatch_t group) {
	char *c = calloc(group.rm_eo - group.rm_so, sizeof(char));
	memcpy(c, &str[group.rm_so], group.rm_eo - group.rm_so);
	return c;
}

static char *glsl_version() {
	int ret;
	regex_t regex;
	if ((ret = regcomp(&regex, GLSL_VERSION_REGEX, REG_EXTENDED)) != 0) {
		err(ret, "failed to compile GLSL version regex");
	}

	char *version = "";
	const char *glsl_version = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
	if (strlen(glsl_version) == 0) {
		printf("Cannot detect GLSL version from %s\n", "GL_SHADING_LANGUAGE_VERSION");
		return version;
	}

	size_t nGroups = 4;
	regmatch_t groups[nGroups];
	ret = regexec(&regex, glsl_version, nGroups, groups, 0);
	if (ret == REG_NOMATCH) {
		printf("Cannot match GLSL version '%s'\n", glsl_version);
	} else if (ret != 0) {
		err(ret, "failed to match GLSL version '%s'", glsl_version);
	} else {
		char *es = extract_group(glsl_version, groups[1]);
		char *major = extract_group(glsl_version, groups[2]);
		char *minor = extract_group(glsl_version, groups[3]);

		if (strcmp(minor, "0") == 0) {
			free(minor);
			minor = malloc(sizeof(char) * 3);
			strcpy(minor, "00");
		}

		bool is100 = strcmp(major, "1") == 0 && strcmp(minor, "00") == 0;
		bool hasES = strcasecmp(es, "ES") == 0 && !is100;

		asprintf(&version, "%s%s%s", major, minor, hasES ? " es" : "");

		free(es);
		free(major);
		free(minor);
	}
	regfree(&regex);

	return version;
}

static void draw_shadertoy(uint64_t start_time, unsigned frame) {
	glUniform1f(iTime, (GLfloat) (get_time_ns() - start_time) / NSEC_PER_SEC);
	// Replace the above to input elapsed time relative to 60 FPS
	// glUniform1f(iTime, (GLfloat) frame / 60.0f);
	glUniform1ui(iFrame, frame);
	
	
	if(updated) { // check if vectors has been updated
	    /*
        printf("Updated iVecs: [%f, %f, %f, %f] [%f, %f, %f, %f] [%f, %f, %f, %f], [%f, %f, %f, %f]", 
        vec0[0], vec0[1], vec0[2], vec0[3],
        vec1[0], vec1[1], vec1[2], vec1[3],
        vec2[0], vec2[1], vec2[2], vec2[3],
        vec3[0], vec3[1], vec3[2], vec3[3]);
        */
        /*
        printf("Updated iVecs: iAix0: [%f, %f, %f, %f]\niAux1: [%f, %f, %f, %f] ", 
        vec0[0], vec0[1], vec0[2], vec0[3],
        vec1[0], vec1[1], vec1[2], vec1[3]);
        */
        glUniform4fv(iAux0, 1, (const GLfloat*)vec0);    
        glUniform4fv(iAux1, 1, (const GLfloat*)vec1);
        glUniform4fv(iAux2, 1, (const GLfloat*)vec2);
        glUniform4fv(iAux3, 1, (const GLfloat*)vec3);
        
        // Reset the flag after print
        updated = 0;
    }
	

	start_perfcntrs();

	glDrawArrays(GL_TRIANGLES, 0, 6);

	end_perfcntrs();
}

int init_shadertoy(const struct gbm *gbm, struct egl *egl, const char *file) {
	int ret;
	char *shadertoy_vs, *shadertoy_fs;
	GLuint program, vbo;
	GLint iResolution;

	const char *shader = load_shader(file);

	const char *version = glsl_version();
	if (strlen(version) > 0) {
		char *invalid;
		long v = strtol(version, &invalid, 10);
		if (invalid == version) {
			printf("failed to parse detected GLSL version: %s\n", invalid);
			return -1;
		}
		char *version_directive;
		asprintf(&version_directive, "#version %s", version);
		printf("Using GLSL version directive: %s\n", version_directive);

		bool is_glsl_3 = v >= 300;
		asprintf(&shadertoy_vs, is_glsl_3 ? shadertoy_vs_tmpl_300 : shadertoy_vs_tmpl_100, version_directive);
		asprintf(&shadertoy_fs, is_glsl_3 ? shadertoy_fs_tmpl_300 : shadertoy_fs_tmpl_100, version_directive, shader);
	} else {
		asprintf(&shadertoy_vs, shadertoy_vs_tmpl_100, version);
		asprintf(&shadertoy_fs, shadertoy_fs_tmpl_100, version, shader);
	}

	ret = create_program(shadertoy_vs, shadertoy_fs);
	if (ret < 0) {
		printf("failed to create program\n");
		return -1;
	}

	program = ret;

	ret = link_program(program);
	if (ret) {
		printf("failed to link program\n");
		return -1;
	}
	
	pthread_t thread_id;
    pthread_create(&thread_id, NULL, socketServer, NULL);

	glViewport(0, 0, gbm->width, gbm->height);
	glUseProgram(program);
	iTime = glGetUniformLocation(program, "iTime");
	iFrame = glGetUniformLocation(program, "iFrame");
	iAux0 = glGetUniformLocation(program, "iAux0");
	iAux1 = glGetUniformLocation(program, "iAux1");
	iAux2 = glGetUniformLocation(program, "iAux2");
	iAux3 = glGetUniformLocation(program, "iAux3");
	
	
	iResolution = glGetUniformLocation(program, "iResolution");
	glUniform3f(iResolution, gbm->width, gbm->height, 0);
	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), 0, GL_STATIC_DRAW);
	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), &vertices[0]);
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) (intptr_t) 0);
	glEnableVertexAttribArray(0);

	egl->draw = draw_shadertoy;

	return 0;
}

A simple python test script which sends new random values every 2 seconds:

import socket
import time
import random

def generate_random_vector():
    return [random.random() for _ in range(4)]

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("127.0.0.1", 1234)) # replace with your server's IP and port if not running on the same machine

while True: 
    vecs = [generate_random_vector() for _ in range(4)]
    data = ' '.join(','.join(str(v) for v in vec) for vec in vecs)

    client_socket.sendall(data.encode())

    time.sleep(2)

client_socket.close()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.