GithubHelp home page GithubHelp logo

patriciogonzalezvivo / glslviewer Goto Github PK

View Code? Open in Web Editor NEW
4.5K 98.0 353.0 206.81 MB

Console-based GLSL Sandbox for 2D/3D shaders

License: BSD 3-Clause "New" or "Revised" License

C++ 84.24% CMake 2.79% HTML 1.94% Makefile 0.10% Python 10.32% Shell 0.07% GLSL 0.54%
shaders fragment-shader c-plus-plus opengl-es glsl vertex-shaders glslviewer c raspberrypi osx

glslviewer's Introduction

glslViewer Donate

GlslViewer is a flexible console-base OpenGL Sandbox to display 2D/3D GLSL shaders without the need of an UI. You can definitely make your own UI or wrapper using the Python Module (include) or any other tool that communicates back/forth with glslViewer through the standard POSIX console In/Out or OSC.

Joing #GlslViewer channel on shader.zone discord to learn how to use it, share work and get help.

GlslViewer gives support to:

  • fragment and vertex shaders on GLSL
  • resolve #include dependencies
  • adding/deleting #define keys through console IN commands and OSC
  • automatically generated set of defines based on the platform, buffer, render pass, geometry attributes and materials properties.
  • passing custom uniforms (float, int, vec2, vec3 and vec4) through console IN or OSC
  • Different kinds of Textures (png, bmp, jpg, tga, hdr, gif, mp4, mov, rtc, rtsp, local camera devices and audio textures)
  • import of Cubemaps and spherical harmonics (png, jpg, tga, hdr)
  • import LST, PLY, OBJ or GLTF files (and their dependencies)
  • default vert/frag shaders for 2D shader and 3D material shaders with PBR lighting model
  • hot reload of files on changes
  • One default light and one default camera
  • Interactive commands thought POSIX console IN/OUT or OSC
  • different debug modes (histogram, textures, buffers, bounding box, etc)
  • shadow maps
  • headless rendering
  • fullscreen and screensaver mode
  • HoloPlay rendering on LookingGlass Display
  • image export
  • PNG sequence export
  • WASM crosscompiling

Wiki themes

Author

Patricio Gonzalez Vivo: github | twitter | instagram | website

Acknowledgements

Thanks to:

glslviewer's People

Contributors

abigpotostew avatar admsyn avatar andystanton avatar anncxx avatar ben-hansske avatar bespsm avatar davl3232 avatar discordianfish avatar djulien avatar doug-moen avatar follower avatar iamrohitanshu avatar ion1 avatar jnsh avatar kamikatze-k2 avatar karimnaaji avatar ludicrousdisplay avatar martinleopold avatar mihaisebea-gl avatar noerw avatar nyamadan avatar patriciogonzalezvivo avatar r21nomi avatar tcoyvwac avatar thezoq2 avatar wilhansen avatar wraybowling avatar xecdesign avatar yvan-sraka avatar zhongruoyu 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glslviewer's Issues

Build glslViewer for Nvidia Jetson TK1 (Ubuntu 15.10)

Installed Ubuntu 14.04 (Ubuntu 14.04.4 LTS) using JetPack TK1 1.2 (October 2015)
https://developer.nvidia.com/embedded/downloads

Followed the build instructions to build glfw (no build problems). Manually set the platform to LINUX in the Makefile, and then build glslViewer. No build errors.

When launching glslViewer with the bunny.frag, no window is opened; but no error is shown either. Control-C will quit glslViewer.

Update: Attached build log
build.txt

Cannot import from ShaderToy via loader

I wanted to read/understand the code of this ShaderToy shader (https://www.shadertoy.com/view/4s2SRt), suggested by the book, but I couldn't do it.

  1. Copy and pasting the code to editor, it gave an error:
x'' : No precision specified for (float)
  1. I've inserted the medium precision snippet at the top, and now it tells me:
'iTime' : undeclared identifier

Isn't there some kind of automatic detection for ShaderToy's variables? Or it is only in glslViewer?

  1. I tried installing glslViewer and use the loader on OS X via brew. Installed fine, but needed requests. OK, I install requests into a virtualenv and launch from there.
glslLoader 4s2SRt
https://www.shadertoy.com/api/v1/shaders/4s2SRt?key=rt8tWH
Traceback (most recent call last):
  File "/usr/local/bin/glslLoader", line 30, in <module>
    if len(data['Shader']['renderpass']) == 1:
KeyError: 'Shader'

Which might make sense, as the above link actually returns "Error": "Shader not found". Is it a bug in ShaderToy?

  1. Anyway, I finally save the shader's code into a .frag file and try to launch glslViewer test.frag, it I get the same error as on editor.
ERROR: 0:132: Use of undeclared identifier 'iTime'
ERROR: 0:133: Use of undeclared identifier 'p'

Can you help me how to import ShaderToy shaders into glslViewer or editor? Should I manually search and replace variables, etc.? Any idea why is the API not working?

Makefile sets PLATFORM incorrectly for RPi running Ubuntu

I'm running Ubuntu MATE on RPi, which causes the Makefile to select PLATFORM_LINUX instead of PLATFORM_RPI. This causes an init error when I try to run glslViewer (not running XWindows).

Just checking the OS is not enough to identify a RPi in this case. I'm not sure what the most appropriate check would be - should it use something like "uname -m" or "uname -p" to check for an ARM CPU, or is there a more reliable way to detect a RPi?

If I force PLATFORM_RPI, then it compiles and runs okay without XWindows running.

Mandelbrot and "__" macros

Hi @doug-moen, I'm getting this error msg on Ubuntu 16.10 64bits together with bad performance on Mandelbrot example

Warnings while compiling examples/mandelbrot.frag:
0:1(9): preprocessor warning: Macro names containing "__" are reserved for use by the implementation.

screen shot 2017-02-21 at 11 46 49 am

Print shader statistics on load

When the user's shader program is loaded, I'd like to print some statistics.
Specifically, the load time in seconds, and the program size or number of instructions.

This provides a rough metric of how expensive the shader is, and is useful if you are trying to optimize a shader by making it load or run faster.

I've got an initial prototype of this. Are you interested in a pull request?
The output looks something like this (on stderr):

shader load time: 2.71828s size: 108242

u_mouse values off by about half the normalized coordinate space

The following snippet works perfectly well in the online editor as well as shadertoy:

#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;

void main() {
    
    vec2 st = gl_FragCoord.xy/u_resolution.xy;
    vec2 normouse = u_mouse.xy / u_resolution.xy;
    
    gl_FragColor = vec4(0.0,0.0,1.0,0.5);
    
    if (normouse.x < st.x) {
        gl_FragColor = vec4(1.0,0.0,0.0,0.5);
    }
    
    if (normouse.y < st.y) {
        gl_FragColor = vec4(0.0,1.0,0.0,0.5);
    }   
}

In glslViewer however, the x-coordinate only works for half the screen, and the y-coordinates seems to by off by about 0.5 (normalized), only filling half the screen when the mouse reaches the top of the window. I'm testing on a 2016 MacBook Pro, with the screen scaled down a bit.

pixel density issues

In getPixelDensity(), we are performing an integer division instead of a floating point division, but returning a float. The devicePixelRatio might not be an integer! "Android phones often have DPRs of 1.5" according to https://www.html5rocks.com/en/mobile/high-dpi/. And this page discusses non-integer pixel scaling ratios on Linux: https://bugzilla.mozilla.org/show_bug.cgi?id=1214470.

When a window is dragged to another monitor with a different pixel density, we should recompute the cached pixel density. This could be done using glfwSetWindowPosCallback.

press esc to close app?

maybe it's just my preference but I think having esc pressed and close the app is much more fail safe in fast iteration development. cmd+q is a little more destructive and I had to be quite cautious of closing sublime. while leaving the app on taking resource significantly so I have to close it pretty often.

Error with pkg-config when compiling

Hi,

I just tried to make GlslViewer to work on local shaders from shadertoy, but I can't compile the app :
It seems to be that pkg-config can't find GLU (glu.pc, I checked and it doesn't exist in the folder /usr/local/lib/pkg-config).

Here is the beginning of the report :

Package glu was not found in the pkg-config search path.
Perhaps you should add the directory containing `glu.pc'
to the PKG_CONFIG_PATH environment variable
Package 'glu', required by 'glew', not found
Package glu was not found in the pkg-config search path.
Perhaps you should add the directory containing `glu.pc'
to the PKG_CONFIG_PATH environment variable
Package 'glu', required by 'glew', not found
g++ -Wall -g -std=c++0x -fpermissive -DRETINA_DISPLAY -DPLATFORM_OSX -stdlib=libc++  src/main.o src/shader.o src/texture.o src/vboMesh.o src/vertexLayout.o -lfreeimage -framework OpenGL  -o glslViewer
Undefined symbols for architecture x86_64:
  "___glewActiveTexture", referenced from:
      Shader::sendUniform(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Texture const*, unsigned int) in shader.o

So how can I link pkg-config ?
Thank !
Technolife

View3d: A viewer for ray-marched 3D shapes

Suppose you create a 3D scene in a fragment shader, using Function
Representation and ray-marching instead of polygons, as seen on shadertoy.com.

For this use case, I have created a 3D browser that allows you to pan, zoom,
and rotate the 3D scene, using the mouse. See PR #69.

The fragment shader uses 3 uniform variables:

uniform vec3 u_eye3d;
uniform vec3 u_centre3d;
uniform vec3 u_up3d;

These are the same quantities that are passed to the lookAt function in GLM
and other libraries.

See the examples menger.frag and raymarch.frag.
These are lightly modified Inigo Quilez demos from shadertoy.com.
Using the viewer, you can fly around and view these models from every perspective.
Eg, you can fly inside the menger sponge, something you can't do with the shadertoy version.

The user interface uses the scroll wheel for zoom, left-button for rotate,
and right-button for pan.

I'd appreciate feedback on the design and the UI.

Raspberry Pi - error while loading shared libraries: libGLESv2.so

I am attempting to get glslViewer up and running on my raspberry pi 3, however when I run apt-get install glslviewer and then attempt to run a test frag, I get the above result. I have tried increasing GPU memory, enabling GL drivers in raspi-config, and installing a few different openGL packages I could find, but nothing works. Just running a glslViewer command with no argument will get the same message as well.

Is there a step I'm missing here?

Full error is:

glslViewer: error while loading shared libraries: libGLESv2.so: cannot open shared object file: No such file or directory

Feature request: Audio input uniform variable

I'm new to GLSL but I'm learning thanks to Book of Shaders (so cool!)

I think it would be amazing to get access to the microphone or other audio input in a uniform vector, as The_Force allows in its bands uniform, which is a vec4(low, mid-low, mid-high, high). I think shaderToy also supports sound input with some kind of channels uniform, but I'm not smart enough to figure that out.

You can plug in a mic or load an audio file, and make shaders react to audio very easily. It's very fun in The_Force and it could be a cool feature in glslViewer, where a command line switch could turn on microphone or listen to the current playing audio or something.

I don't know C++ very well at all, or how hard this would be to do on different platforms. But I may look into it someday soon and send a pull request if I figure it out! If you think this is a dumb idea, feel free to close this issue, I won't be offended. Haha.

Thanks for making this cool tool!

add shadertoy support

I would like to add simple support for shadertoy image shaders:

  • if iGlobalTime is referenced, define the iGlobalTime uniform
  • if iResolution is referenced, define the iResolution uniform
  • if mainImage is defined, define a main() function that calls it

Shadertoy scripts are recognized automatically based on their content, not by a command line flag.

If I get this working, are you interested in a pull request for this change?

recognize iTime from shadertoy shaders

I've been playing around with glslViewer, and I've notices that all the shadertoy shaders use iTime, but glslViewer only recognizes iGlobalTime. I'm not sure if there's a difference between the two, but I've been putting a simple #define iTime iGlobalTime at the beginning of those shadertoy ones, and they work fine then. Is there any chance of getting glslViewer to permanently recognize iTime?

I should note this is on MacOS and I installed it via homebrew.

Bug: glslViewer consumes high CPU cylces when window out of focus

Mac 10.10.

Build a working frag file on glslViewer (sublime or via terminal) such as the included test.frag. Then open Activity Monitor as the front most window on the system. Watch as the CPU% jumps up to ~75%. When returning the glslViewer instance back to focus, CPU% drops back to more expected / average level of 2-15%.

Add support for #version directive

Currently I'm unable to test any shaders that contain a #version directive due to the following error, even if the #version statement is made at the very beginning of the file:

Errors while compiling fragment shader:
0(2) : error C0204: version directive must be first statement and may not be repeated

Additionally, I've confirmed that I am indeed using a proper OpenGL 4.x context.

Upon further investigation, I've found that because Shader::compileShader() appends a prologue to the shader, the version statement will never truly be at the beginning of the file.

Errors on RPI

@doug-moen This is happening on RPI:

CompiledWarnings while compiling examples/test.frag:
CompiledError linking shader: ERROR:PREPROCESSOR-1 (fragment shader, line 1) Preprocessor syntax error : reserved macro name
1: #ifdef GL_ES
Warnings while compiling shader:
CompiledWarnings while compiling shader:
Compiled

screen shot 2017-02-21 at 12 10 16 pm

core dump while resizing window

This happened with my own build on Ubuntu 16.04.
I can reproduce it at will, by repeatedly grabbing the window edge and resizing it: eventually it crashes. Takes about 10 resizes before it crashes.

(gdb) bt
#0  0x00007fab0da9a428 in __GI_raise (sig=sig@entry=6)
    at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007fab0da9c02a in __GI_abort () at abort.c:89
#2  0x00007fab0da92bd7 in __assert_fail_base (fmt=<optimized out>, 
    assertion=assertion@entry=0x47d7a8 "abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0)", 
    file=file@entry=0x47d778 "include/glm/gtx/../gtc/matrix_transform.inl", 
    line=line@entry=236, 
    function=function@entry=0x47d800 <glm::tmat4x4<double, (glm::precision)0> glm::perspectiveRH<double>(double, double, double, double)::__PRETTY_FUNCTION__> "glm::tmat4x4<T, (glm::precision)0u> glm::perspectiveRH(T, T, T, T) [with T = double]") at assert.c:92
#3  0x00007fab0da92c82 in __GI___assert_fail (
    assertion=assertion@entry=0x47d7a8 "abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0)", 
    file=file@entry=0x47d778 "include/glm/gtx/../gtc/matrix_transform.inl", 
    line=line@entry=236, 
    function=function@entry=0x47d800 <glm::tmat4x4<double, (glm::precision)0> glm::perspectiveRH<double>(double, double, double, double)::__PRETTY_FUNCTION__> "glm::tmat4x4<T, (glm::precision)0u> glm::perspectiveRH(T, T, T, T) [with T = double]") at assert.c:101
#4  0x000000000046d6fa in glm::perspectiveRH<double> (zFar=<optimized out>, 
    zNear=<optimized out>, aspect=<optimized out>, fovy=<optimized out>)
    at include/glm/gtx/../gtc/matrix_transform.inl:236
#5  glm::perspective<double> (zFar=<optimized out>, zNear=<optimized out>, 
    aspect=<optimized out>, fovy=<optimized out>)
    at include/glm/gtx/../gtc/matrix_transform.inl:223
#6  Camera::updateCameraSettings (this=0x68a6a0 <cam>) at src/3d/camera.cpp:68
#7  Camera::setViewport (this=this@entry=0x68a6a0 <cam>, 
    _width=_width@entry=0, _height=_height@entry=0) at src/3d/camera.cpp:15
#8  0x000000000042ec48 in onViewportResize (_newWidth=0, _newHeight=0)
    at src/main.cpp:647
#9  0x0000000000431e85 in setWindowSize (_width=<optimized out>, 
    _height=<optimized out>) at src/app.cpp:419
#10 0x0000000000432094 in <lambda(GLFWwindow*, int, int)>::operator() (
    __closure=0x0, _window=<optimized out>, _h=500, _w=607) at src/app.cpp:211
#11 <lambda(GLFWwindow*, int, int)>::_FUN(GLFWwindow *, int, int) ()
    at src/app.cpp:212
#12 0x00007fab0eb891bd in ?? () from /usr/lib/x86_64-linux-gnu/libglfw.so.3
#13 0x00000000004319d1 in updateGL () at src/app.cpp:379
#14 0x0000000000419731 in main (argc=<optimized out>, argv=<optimized out>)
    at src/main.cpp:281

Bug: orphaned glslViewer process from consecutive builds consumes high CPU

I'm on Mac OS 10.10 using Sublime Text 3 and the glslViewer plugin.

It seem like a master or slave thread gets "lost" during all the building steps and gets stuck in an infinite loop. After taking the following steps, one of the glslViewer processes gets stuck into this loop consuming 50-100% of my CPU. The thread also gets disconnected from Sublime and the must be force quit from Activity Monitor.

Steps:

  1. Open a frag file containing a compile error. ( you can use an empty file or any frag file with a compile error).
  2. Build it with Cmd-B (automatic build system)
  3. Return focus back to sublime and auto-build again (Cmd-B) (two blank glslViewer windows should be open)
  4. Return focus to Sublime, save file (Cmd-S)
  5. Build again (Cmd-B)
  6. Looking at Activity Monitor, there is 6 threads, one or two of which are using very high CPU.

I realize this isn't how you intended this program to be used since you have watch file functionality. However I run into this when opening and building various different shaders at the same time. It's just a minor issue for me. Thanks 👍

Console IN Commands + Rendering Question

I just started using this plug-in for sublime text 3 and I love it already! However, I ran into an issue I was hoping someone could help me with.

Where are the png sequences saved after rendering in headless mode? After entering the command it returns:
// Will exit in 1 seconds.
// Will save screenshot to TestRender.png on exit.
// Screenshot saved to TestRender.png

However, when I search my computer for TestRender.png it is no where to be found.

Thank you for any assistance that can be provided.

preprocessor error: #version must appear on the first line

I'm receiving the following error when trying to include a version preprocessing line in my fragment shader.
0:1(1): preprocessor error: #version must appear on the first line
If i comment out the version, //#version 100 everything works fine. I can leave the version line in the online editor here:
http://thebookofshaders.com/edit.php?log=170427231821

#version 100
#ifdef GL_ES
precision mediump float;
#endif

void main()
{
	// gl_FragCoord contains the window relative coordinate for the fragment.
	// we use gl_FragCoord.x position to control the red color value.
	// we use gl_FragCoord.y position to control the green color value.
	// please note that all r, g, b, a values are between 0 and 1.

	float windowWidth = 1024.0;
	float windowHeight = 768.0;

	float r = gl_FragCoord.x / windowWidth;
	float g = gl_FragCoord.y / windowHeight;
	float b = 1.0;
	float a = 1.0;
	gl_FragColor = vec4(r, g, b, a);
}

Feature request: User specify max FPS

I notice the fan of my laptop starts working hard when I bring up glslViewer. I think the GPU/CPU or something is doing more work than it needs to. Much of what I do does not really require a new frame every 1/60 of a second. It would be nice to have a FPS limiter.

Render shader to an image sequence

I want to render the video a shader generates to an image sequence. Can I do that? If not, can you add this feature? Or possibly hint me at another tool. :)

Error running shader on boot

I tried making glslViewer run on boot so it could be part of an installation. So I added this to my .bashrc

# start video synth
glslViewer ~/Villarossa/vengance.frag -w 640 -h 480

I tried a couple of different methods, local.rc and .bashrc Using .bashrc seemed like the better option since local.rc will complain if there is any text output of any kind. But I just get this error, regardless of the permissions set on the application or the shader file.

Error watching file /home/Villarossa/vengance.frag
Usage: glslViewer shader.frag [shader.vert] [mesh.(obj/.ply)] [texture.(png/jpg)] [-textureNameA texture.(png/jpg)] [-u] [-x x] [-y y] [-w width] [-h height] [-l/--livecoding] [--square] [-s seconds] [-o screenshot.png]

Update: same error using the init.d method

Note: this is on Raspbian GNU/Linux 8 on a Pi 2

strict-aliasing warning messages in GLM

These messages are a bug in GLM that was fixed in release 0.9.7.1.
g-truc/glm#370

In file included from include/glm/detail/func_packing.hpp:197:0,
                 from include/glm/packing.hpp:35,
                 from include/glm/glm.hpp:113,
                 from src/gl/shader.h:6,
                 from src/gl/vertexLayout.h:8,
                 from src/gl/vbo.h:6,
                 from src/ui/cursor.h:3,
                 from src/ui/cursor.cpp:1:
include/glm/detail/func_packing.inl: In function ‘glm::uint glm::packUnorm2x16(const vec2&)’:
include/glm/detail/func_packing.inl:42:47: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   return reinterpret_cast<uint const &>(Topack);
                                               ^
include/glm/detail/func_packing.inl: In function ‘glm::vec2 glm::unpackUnorm2x16(glm::uint)’:
include/glm/detail/func_packing.inl:47:50: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   vec2 Unpack(reinterpret_cast<u16vec2 const &>(p));
                                                  ^
include/glm/detail/func_packing.inl: In function ‘glm::uint glm::packSnorm2x16(const vec2&)’:
include/glm/detail/func_packing.inl:54:47: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   return reinterpret_cast<uint const &>(Topack);
                                               ^
include/glm/detail/func_packing.inl: In function ‘glm::vec2 glm::unpackSnorm2x16(glm::uint)’:
include/glm/detail/func_packing.inl:59:56: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   vec2 const Unpack(reinterpret_cast<i16vec2 const &>(p));
                                                        ^
include/glm/detail/func_packing.inl: In function ‘glm::uvec2 glm::unpackDouble2x32(double)’:
include/glm/detail/func_packing.inl:98:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   return reinterpret_cast<uvec2 const &>(v);
                                           ^
include/glm/detail/func_packing.inl:98:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
include/glm/detail/func_packing.inl: In function ‘glm::uint glm::packHalf2x16(const vec2&)’:
include/glm/detail/func_packing.inl:107:47: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   return reinterpret_cast<uint const &>(Unpack);
                                               ^
include/glm/detail/func_packing.inl: In function ‘glm::vec2 glm::unpackHalf2x16(glm::uint)’:
include/glm/detail/func_packing.inl:112:59: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   i16vec2 const Unpack(reinterpret_cast<i16vec2 const &>(v));
                                                           ^
include/glm/detail/func_packing.inl:112:60: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   i16vec2 const Unpack(reinterpret_cast<i16vec2 const &>(v));

Make error with glm on OSX

hi! i get the following error when i try to make:

λ brucemacpro glslViewer → λ git master* → make
src/3d/node.o
g++ -Wall -g -std=c++0x -fpermissive -DPLATFORM_OSX -stdlib=libc++ -I/usr/local/Cellar/glfw3/3.1.1/include  -I/usr/local/include/ -Isrc/ -Iinclude/ -O3 -I//Library/Frameworks/GLUI.framework -g -c src/3d/node.cpp -o src/3d/node.o -Wno-deprecated-declarations
In file included from src/3d/node.cpp:3:
In file included from /usr/local/include/glm/gtx/matrix_decompose.hpp:70:
/usr/local/include/glm/gtx/matrix_decompose.inl:128:11: error: no viable overloaded '='
                        Row[i] = LocalMatrix[i];
                        ~~~~~~ ^ ~~~~~~~~~~~~~~
src/3d/node.cpp:22:10: note: in instantiation of function template specialization 'glm::decompose<float, 0>' requested here
    glm::decompose(m_transformMatrix, m_scale, m_orientation, m_position, skew, perspective );
         ^
/usr/local/include/glm/detail/type_vec3.hpp:49:9: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'col_type'
      (aka 'tvec4<float, (glm::precision)0U>') to 'const glm::tvec3<float, 0>' for 1st argument
        struct tvec3
               ^
/usr/local/include/glm/detail/type_vec3.hpp:49:9: note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'col_type'
      (aka 'tvec4<float, (glm::precision)0U>') to 'glm::tvec3<float, 0>' for 1st argument
        struct tvec3
               ^
/usr/local/include/glm/detail/type_vec3.hpp:188:31: note: candidate template ignored: could not match 'tvec3' against 'tvec4'
                GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<U, P> const & v);
                                            ^
In file included from src/3d/node.cpp:3:
In file included from /usr/local/include/glm/gtx/matrix_decompose.hpp:70:
/usr/local/include/glm/gtx/matrix_decompose.inl:133:3: error: no matching function for call to 'v3Scale'
                v3Scale(Row[0], 1.0);
                ^~~~~~~
/usr/local/include/glm/gtx/matrix_decompose.inl:47:26: note: candidate template ignored: deduced conflicting types for parameter 'T' ('float' vs. 'double')
        GLM_FUNC_QUALIFIER void v3Scale(tvec3<T, P> & v, T desiredLength)
                                ^
/usr/local/include/glm/gtx/matrix_decompose.inl:137:12: error: no matching function for call to 'combine'
                Row[1] = combine(Row[1], Row[0], 1.0, -Skew.z);
                         ^~~~~~~
/usr/local/include/glm/gtx/matrix_decompose.inl:38:33: note: candidate template ignored: deduced conflicting types for parameter 'T' ('float' vs. 'double')
        GLM_FUNC_QUALIFIER tvec3<T, P> combine(
                                       ^
/usr/local/include/glm/gtx/matrix_decompose.inl:141:3: error: no matching function for call to 'v3Scale'
                v3Scale(Row[1], 1.0);
                ^~~~~~~
/usr/local/include/glm/gtx/matrix_decompose.inl:47:26: note: candidate template ignored: deduced conflicting types for parameter 'T' ('float' vs. 'double')
        GLM_FUNC_QUALIFIER void v3Scale(tvec3<T, P> & v, T desiredLength)
                                ^
/usr/local/include/glm/gtx/matrix_decompose.inl:146:12: error: no matching function for call to 'combine'
                Row[2] = combine(Row[2], Row[0], 1.0, -Skew.y);
                         ^~~~~~~
/usr/local/include/glm/gtx/matrix_decompose.inl:38:33: note: candidate template ignored: deduced conflicting types for parameter 'T' ('float' vs. 'double')
        GLM_FUNC_QUALIFIER tvec3<T, P> combine(
                                       ^
/usr/local/include/glm/gtx/matrix_decompose.inl:148:12: error: no matching function for call to 'combine'
                Row[2] = combine(Row[2], Row[1], 1.0, -Skew.x);
                         ^~~~~~~
/usr/local/include/glm/gtx/matrix_decompose.inl:38:33: note: candidate template ignored: deduced conflicting types for parameter 'T' ('float' vs. 'double')
        GLM_FUNC_QUALIFIER tvec3<T, P> combine(
                                       ^
/usr/local/include/glm/gtx/matrix_decompose.inl:152:3: error: no matching function for call to 'v3Scale'
                v3Scale(Row[2], 1.0);
                ^~~~~~~
/usr/local/include/glm/gtx/matrix_decompose.inl:47:26: note: candidate template ignored: deduced conflicting types for parameter 'T' ('float' vs. 'double')
        GLM_FUNC_QUALIFIER void v3Scale(tvec3<T, P> & v, T desiredLength)
                                ^
7 errors generated.
make: *** [src/3d/node.o] Error 1

GLFW/glfw3.h file not found

(First, wow: this document is super amazing. Thank you!)

I'm trying to install the examples using the Mac instructions. But when using the make command I get the following error:

Package glfw3 was not found in the pkg-config search path.
Perhaps you should add the directory containing `glfw3.pc'
to the PKG_CONFIG_PATH environment variable
No package 'glfw3' found
src/main.o
g++ -Wall -g -std=c++0x -fpermissive -DPLATFORM_OSX -stdlib=libc++  -I/usr/local/include/ -Isrc/ -I//Library/Frameworks/GLUI.framework -g -c src/main.cpp -o src/main.o -Wno-deprecated-declarations
In file included from src/main.cpp:11:
In file included from src/platform.h:8:
src/gl.h:4:10: fatal error: 'GLFW/glfw3.h' file not found

Not sure if this is an error with my setup, or with the code :)

Can't compile on Kali Linux

I tried to make this work in Kali Linux but doesn't seem to compile.
Kali is based on Debian, yet, I have no idea how this should work.

Any ideas?

Is `brew upgrade` a good idea?

This is kind of nitpicky but does it really make sense to include brew upgrade in the Mac install instructions? On any machine with a large number of packages you might spend all day upgrading unrelated packages, or even upgrading packages that you might not want changed.

Seems like more of a "if it doesn't work, try running brew upgrade first"?

MakeFile error on osx

Hi Patricio,

I have installed homebrew and glfw as per your instructions for osx but when I get to the make command I am getting the following error. Any ideas how to resolve this? Thanks :)

Joshuas-MBP:glslViewer josh$ make
make: pkg-config: Command not found
src/main.o
g++ -Wall -g -std=c++0x -fpermissive -DPLATFORM_OSX -stdlib=libc++ -I/usr/local/include/ -Isrc/ -I//Library/Frameworks/GLUI.framework -g -c src/main.cpp -o src/main.o -Wno-deprecated-declarations
make: pkg-config: Command not found
src/shader.o
g++ -Wall -g -std=c++0x -fpermissive -DPLATFORM_OSX -stdlib=libc++ -I/usr/local/include/ -Isrc/ -I//Library/Frameworks/GLUI.framework -g -c src/shader.cpp -o src/shader.o -Wno-deprecated-declarations
make: pkg-config: Command not found
src/texture.o
g++ -Wall -g -std=c++0x -fpermissive -DPLATFORM_OSX -stdlib=libc++ -I/usr/local/include/ -Isrc/ -I//Library/Frameworks/GLUI.framework -g -c src/texture.cpp -o src/texture.o -Wno-deprecated-declarations
make: pkg-config: Command not found
src/vboMesh.o
g++ -Wall -g -std=c++0x -fpermissive -DPLATFORM_OSX -stdlib=libc++ -I/usr/local/include/ -Isrc/ -I//Library/Frameworks/GLUI.framework -g -c src/vboMesh.cpp -o src/vboMesh.o -Wno-deprecated-declarations
make: pkg-config: Command not found
src/vertexLayout.o
g++ -Wall -g -std=c++0x -fpermissive -DPLATFORM_OSX -stdlib=libc++ -I/usr/local/include/ -Isrc/ -I//Library/Frameworks/GLUI.framework -g -c src/vertexLayout.cpp -o src/vertexLayout.o -Wno-deprecated-declarations
make: pkg-config: Command not found
make: pkg-config: Command not found
g++ -Wall -g -std=c++0x -fpermissive -DPLATFORM_OSX -stdlib=libc++ -I/usr/local/include/ src/main.o src/shader.o src/texture.o src/vboMesh.o src/vertexLayout.o -lfreeimage -framework OpenGL -L/usr/local/lib/ -o glslViewer
Undefined symbols for architecture x86_64:
"_glfwCreateWindow", referenced from:
initGL(int, char**) in main.o
"_glfwGetFramebufferSize", referenced from:
fixDpiScale() in main.o
"_glfwGetMouseButton", referenced from:
handleCursor(GLFWwindow*, double, double) in main.o
"_glfwGetWindowSize", referenced from:
fixDpiScale() in main.o
"_glfwInit", referenced from:
initGL(int, char**) in main.o
"_glfwMakeContextCurrent", referenced from:
initGL(int, char**) in main.o
"_glfwPollEvents", referenced from:
updateGL() in main.o
"_glfwSetCursorPosCallback", referenced from:
initGL(int, char**) in main.o
"_glfwSetKeyCallback", referenced from:
initGL(int, char**) in main.o
"_glfwSetWindowShouldClose", referenced from:
handleKeypress(GLFWwindow*, int, int, int, int) in main.o
"_glfwSetWindowSizeCallback", referenced from:
initGL(int, char**) in main.o
"_glfwSwapBuffers", referenced from:
renderGL() in main.o
"glfwTerminate", referenced from:
initGL(int, char*
) in main.o
closeGL() in main.o
"glfwWindowShouldClose", referenced from:
isGL() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *
* [glslViewer] Error 1

Headless instance does not output image

Hello there,

I've been learning a lot with "The Book of Shaders" and have been using glslViewer to code, thanks so much for publishing them!

One thing I've wanted to do is to export an image from glslViewer. Reading the documentation i see there's a method to do this by creating a PNG image from a headless instance of the viewer, however when I attempt to do:

glslViewer myShader.frag --headless -s 1 -o Myname.png

I get this message in the console: "Will save screenshot to Myname.png on exit." and after exiting the instance I get no image at all in the current directory. Is this file being exported to another specific directory or is this a bug?

Thanks a lot!
Darien

build on ubuntu 16.04 using libglfw3-dev package

I built glslViewer on Ubuntu 16.04. Instead of building glfw myself, I installed the package:
$ sudo apt-get install libglfw3-dev

This installed version 3.1 of the library, which is somewhat behind the latest released version.
One small change was required to make this compile:

--- a/src/app.cpp
+++ b/src/app.cpp
@@ -189,7 +189,7 @@ void initGL (glm::ivec4 &_viewport, bool _headless) {
         }
 
         if (_headless) {
-            glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
+            glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
         }

With this change, all the examples work as expected.

Would you like me to submit a pull request for this change?

Shadertoy buffer support

I realize this is a way bigger ask than the other shadertoy features that you have included already, but it would be a really nice one, especially for the ability to do things that are easier with feedback shaders (i.e. light propagation, CA, physics, interactive particle systems). I notice that there is already support for a backbuffer, but multiple buffer support would allow for things like : https://www.shadertoy.com/view/XdtSRn

The major things I think this would require would be:

  • support for passing multiple frag shaders at the command line
  • internally use ping pong fbos for buffer shaders
  • be able to reference the texture uniforms from the fbos

I think it would also cause compatibility issues with https://github.com/patriciogonzalezvivo/sublime-glslViewer - but just posting here to start a conversation about whether it is something that is wanted or not.

Strange behaviour when adding texture with name

main.fsh:

uniform sampler2D u_tex0;
uniform vec2 u_tex0Resolution;

void main() {
    vec2 currentCoord = vec2(gl_FragCoord.x / u_tex0Resolution.x, gl_FragCoord.y / u_tex0Resolution.y);
    vec4 pixel = texture2D(u_tex0, currentCoord);
    gl_FragColor = pixel;
}

terminal:

$ glslViewer main.fsh 01.jpg

output:
screen shot 2015-10-13 at 9 51 45 am

terminal:

$ glslViewer main.fsh -tex0 01.jpg

screen shot 2015-10-13 at 9 52 07 am

-D option usage?

It seems like #define MY_DEFINE 100 would translate to glslViewer mything.frag -D MY_DEFINE 100, but this does not work. Am I using this incorrectly, or is this broken?

glfw git clone is borked (Permission denied)

root@tcll-AY589AAR-ABA-a4317c:~# git clone [email protected]:glfw/glfw.git
Cloning into 'glfw'...
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

why not simply:

sudo apt-get install glslViewer

Feature Request: Always on Top

I would absolutely love to request an always on top feature for osX ( not sure if it's there on win ).

Having tried out the pi edition, it's amazing having glslViewer just running in the corner. It would be great to do that in an environment of choice. Could be the same -l flag.

non-interactive PNG output

I would like

   glslViewer --headless -o foo.png foo.frag

to create a PNG file and exit immediately. Currently, it pauses forever, without opening an OpenGL window.

I've implemented this in a local workspace. Will you accept a pull request for this?

compile error on Ubuntu 14.04

I followed the installation instruction and I am getting compilation error

g++ -o glslViewer -Wl,--whole-archive include/tinyobjloader/tiny_obj_loader.cc src/app.o src/main.o src/utils.o src/3d/camera.o src/3d/node.o src/gl/shader.o src/gl/texture.o src/gl/vbo.o src/gl/vertexLayout.o src/types/mesh.o src/types/polarPoint.o src/types/polyline.o src/types/rectangle.o src/types/shapes.o src/ui/cursor.o -L/usr/local/lib -lglfw3 -lGLU -lGL -lXrandr -lXi -lXxf86vm -lXcursor -lXinerama -lXrender -lX11 -lXext -lXdamage -lXfixes -lpthread -Wl,--no-whole-archive -rdynamic
/usr/bin/ld: /usr/local/lib/libglfw3.a(glx_context.c.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [glslViewer] Error 1

Could you let me know how to solve this?

P.S: Would it be possible to have a cmake file for this so it can also work on windows?

system freeze with Intel graphics on Linux

I switched my Ubuntu 16.04 system to Intel graphics (for testing purposes). Slow, complicated shader programs work fine in glslViewer. But short, simple shader programs cause the desktop UI to freeze, requiring a reboot.

For example, here's the shadertoy.com "hello world" program:

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
fragColor = vec4(uv,0.5+0.5*sin(iGlobalTime),1.0);
}

This program runs fine on the shadertoy.com website, inside Firefox. But give the same program to glslViewer and we need to reboot. The problem, apparently, is that glslViewer runs shader programs at max frame rate, with no throttling. If the shader program is too simple and fast, then BOOM.

Build fail on pinebook - armbian

Hello! tried to build on pinebook + armbian:

luruke@pinebook:~/git/glslViewer$ uname -a
Linux pinebook 3.10.107-pine64 #3 SMP PREEMPT Mon Jun 4 16:56:16 UTC 2018 aarch64 aarch64 aarch64 GNU/Linux
luruke@pinebook:~/git/glslViewer$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.5 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.5 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

Build:

https://pastebin.com/TA3fH1B8

supply a download of the built glslViewer for macOS

hello,

i have tried building this a few times through brew, but it does error. i have resorted to uninstalling then installing but no dice.

could you by chance suppyl a download of the built file? i know i place it in /usr/local/bin/ but would like to do it that way, rather than download loads of things again and again.

thanks

u_view2d

Check out my new PR #49. It introduces a new uniform, u_view2d, a transform matrix which is used by a fragment shader to pan and zoom around in a 2D scene.

The best way to understand it is to compile the program then run examples/mandelbrot.frag.
Use left-mouse-button drag to pan around, and use the mouse scroll wheel or multi-touch trackpad to zoom in and out. Then look at the source code for mandelbrot.frag to see how u_view2d is used.

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.