"Questions that don't deserve their own thread" thread

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Locked
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: "Questions that don't deserve their own thread" thread

Post by bobbyjones »

Ranguna259 wrote:
bobbyjones wrote:You don't need to. Just ship the binaries and load them up. You don't have to recompile love for them.
The problem is I can't find the binaries anywhere, I can't compile the code on windows and I wasn't talking about recompiling love, I wanted to compile the code through luaJIT's FFI, which would load the c code inside Lua.
That seems complicated. I mean you probably could try that but I think it would probably take awhile for it to compile. Rather than doing that it would be much better and faster if you just used ffi to wrap libcrypto. That way you can just wrap what you need.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: "Questions that don't deserve their own thread" thread

Post by Ranguna259 »

That's what I said, compile luacrypto though FFI, but I don't know how to do that either.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: "Questions that don't deserve their own thread" thread

Post by bobbyjones »

No meant use ffi to wrap libcrypto which should be available everywhere.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: "Questions that don't deserve their own thread" thread

Post by Ranguna259 »

And how would I do that ?
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: "Questions that don't deserve their own thread" thread

Post by bobbyjones »

Here is an example of an ffi binding. It will result in a faster binding and should be easier because libcrypto is part of openssl so it should be available everywhere. And if it's not it will have binaries for everywhere.
https://github.com/LPGhatguy/luajit-request

Edit: just in case it was unclear (I usually do make unclear posts) the example was not an example of libcrypto but just of ffi bindings in general.
binaryeye
Prole
Posts: 8
Joined: Wed Feb 03, 2016 2:58 pm

Re: "Questions that don't deserve their own thread" thread

Post by binaryeye »

I'm new to writing shaders and having some trouble. I'm using six specific colors in my game, each with a bright and dark version like the CGA palette (e.g. light red is 255/85/85, dark red is 170/0/0, etc.). I'm attempting to implement a "water" shader that returns light cyan (85/255/255) for all light colors and dark cyan (0/170/170) for all dark colors. The code below is returning light cyan even for dark colors and I don't understand why. What am I doing wrong? Any help would be appreciated!

Code: Select all

    vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
      vec4 pixel = Texel(texture, texture_coords);
      if (pixel.a > 0.0) {              
        if (pixel.r == 1.0 || pixel.g == 1.0 || pixel.b == 1.0) return vec4(85.0/255.0, 1.0, 1.0, 1.0);
        else return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0);        
      }            
    }
I'd also like the shader to catch light gray (170/170/170) as a light color, but at this point I'd simply like to learn why the above doesn't work.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: "Questions that don't deserve their own thread" thread

Post by Ranguna259 »

I belive you forgot to open brackets on the second if, try this:

Code: Select all

    vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
      vec4 pixel = Texel(texture, texture_coords);
      if (pixel.a > 0.0) {              
        if (pixel.r == 1.0 || pixel.g == 1.0 || pixel.b == 1.0) {
          return vec4(85.0/255.0, 1.0, 1.0, 1.0);
       } 
       return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0);        
      }            
    }
But your code will return vec4(85.0/255.0, 1.0, 1.0, 1.0) for all pixel that have at least one of their rgb values set to 255 and it will return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0) for all other pixels.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
Evine
Citizen
Posts: 72
Joined: Wed May 28, 2014 11:46 pm

Re: "Questions that don't deserve their own thread" thread

Post by Evine »

Something like this might work:

Code: Select all

    vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
      vec4 pixel = Texel(texture, texture_coords);
      if (pixel.a > 0.0) {              
        if (pixel.r > (254.5/255.0) || pixel.g > (254.5/255.0) || pixel.b > (254.5/255.0))
        	return vec4(85.0/255.0, 1.0, 1.0, 1.0);
        else
        	return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0);        
      }            
    }
Doing "==" comparison on floating point numbers is always a bit finicky. So I changed it so it checks if the input value is greater than 254.5 instead.

Also code readability is nice. So i'd recommend at least putting if statements and code on separate lines.
Artal, A .PSD loader: https://github.com/EvineDev/Artal
binaryeye
Prole
Posts: 8
Joined: Wed Feb 03, 2016 2:58 pm

Re: "Questions that don't deserve their own thread" thread

Post by binaryeye »

Thanks for the suggestions. Unfortunately, neither work. I tried both in my actual game code as well as a separate test file, and both return light cyan when given dark red.
Evine wrote:Doing "==" comparison on floating point numbers is always a bit finicky. So I changed it so it checks if the input value is greater than 254.5 instead.
I figured as much. My original approach was to check if the sum of the RGB channels is greater than 1.5. The highest value dark color (e.g. 170/170/0) sums to 1.333; the lowest value bright color (e.g. 255/85/85) sums to 1.666. But this doesn't work, either. I've attached an example file. The draw color is set to 170/0/0 and the shader code is this:

Code: Select all

    vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
      vec4 pixel = Texel(texture, texture_coords);
      if (pixel.a > 0.0) {              
        if ((pixel.r + pixel.g + pixel.b) > 1.5)
          return vec4(85.0/255.0, 1.0, 1.0, 1.0);
        else
          return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0);        
      }            
    }
I'm beginning to wonder if it's my machine, but I'm using another shader that works fine.
Attachments
shader_test.love
(904 Bytes) Downloaded 93 times
User avatar
Evine
Citizen
Posts: 72
Joined: Wed May 28, 2014 11:46 pm

Re: "Questions that don't deserve their own thread" thread

Post by Evine »

Ah now I see the mistake you made. When you're using shaders the color that is set with love.graphics.setColor() and the pixel color of an image is two different arguments passed into the shader. "vec4 color" being the love.graphics.setColor() color and "Image texture" being the image pixels.

Because a primitive shape pixel color can only be vec4(0,0,0,0) or vec4(1,1,1,1) you only need to an if on the color value.

Code: Select all

    vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
      vec4 pixel = Texel(texture, texture_coords);
      if (pixel.a > 0.0) {              
        if ((color.r + color.g + color.b) > 1.5)
          return vec4(85.0/255.0, 1.0, 1.0, 1.0);
        else
          return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0);        
      }            
    }
Artal, A .PSD loader: https://github.com/EvineDev/Artal
Locked

Who is online

Users browsing this forum: Google [Bot] and 45 guests