Skip to content

Instantly share code, notes, and snippets.

@GunnarKarlsson
GunnarKarlsson / gist:69324641c0c756aecc9b2e8342d35dc0
Created December 10, 2018 03:30
basic client server example in c++with sockets
//server.cpp
#include <iostream>
#include <unistd.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>
#define PORT 8080
@GunnarKarlsson
GunnarKarlsson / edgerenderer.h
Created November 8, 2018 05:20
edge renderer
#version 410 core
in vec2 TexCoord;
uniform sampler2D screenTexture;
out vec4 FragColor;
const float offset = 1.0 / 300.0;
vec3 setContrast(vec3 value, float contrast)
{
return (value - 0.5) * contrast + 0.5;
#ifndef LINEUTIL_H
#define LINEUTIL_H
#include "common.h"
/*
** Draws horizontal line
** hexRgb = e.g. 0xFF0000
*/
void drawHLine(int x1, int x2, int y, GLubyte *data, unsigned long hexRgb, int width, int height)
@GunnarKarlsson
GunnarKarlsson / gist:06d64597b52f2dabe988a61fe80b6c4c
Created May 8, 2018 14:38
Fragment shader: square follows mouse
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec3 col1 = vec3(0.5, 0.5, 0.5);
vec3 col2 = vec3(0.0, 1.0, 1.0);
vec3 col = col1;
if (fragCoord.x > iMouse.x - 30.0 &&
fragCoord.x < iMouse.x + 30.0 &&
fragCoord.y > iMouse.y - 30.0 &&
@GunnarKarlsson
GunnarKarlsson / circle_mouse_frag_shader.txt
Last active September 12, 2018 01:32
Frag shader: circle follows mouse
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec3 col = vec3(0.5, 0.5, 0.5);
float radius = 50.0;
float dist_squared = dot(iMouse.xy - fragCoord.xy, iMouse.xy - fragCoord.xy);
if (dist_squared < (radius * radius)) {
col += vec3(0.0, 1.0, 1.0);
}
fragColor = vec4(col,1.0);
}
@GunnarKarlsson
GunnarKarlsson / gist:15d9921a4b64b8295098c352516e9e5f
Created April 23, 2018 14:26
Shader maker animated texture
// simple vertex shader
varying vec2 texCoord;
uniform float time;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
#include <SFML/Window.hpp>
#include <OpenGL/gl3.h>
#include <iostream>
#include <fstream>
using namespace std;
// Read a shader source from a file
// store the shader source in a std::vector<char>
void read_shader_src(const char *fname, std::vector<char> &buffer) {
@GunnarKarlsson
GunnarKarlsson / outlineshader.shader
Created July 29, 2017 10:06
Outline shader for Unity
Shader "squidzoo/Outline"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_OutlineColor("Outline color", Color) = (0,0,0,1)
_OutlineWidth("Outline width", Range(1.0,5.0)) = 1.05
}
CGINCLUDE
public class CardController : MonoBehaviour {
public Sprite frontSprite;
public Sprite backSprite;
public float uncoverTime = 12.0f;
// Use this for initialization
void Start () {
GameObject card = new GameObject("Card"); // parent object
GameObject cardFront = new GameObject("CardFront");
// Author @patriciogv - 2015
// http://patriciogonzalezvivo.com
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;