Dear Magnificent Community and Developers,
There's a PixiJs filter which is based on a shader ""Godrays" by alaingalvan", but it is required to somehow achieve such a filter/shader which does lighten certain areas where "lights" exist on a transparent stage without darkening the background.
The current version creates dark places ('0x000000') where the "lights" are not shown, but the darkness must not surpass the background ('0x333333' or '0xffffff' as in CSS), so it would look like a transparent filter in the result. This is the incorrect behavior since it creates black background where the "lights" are (it is correct that it affects the background):
const uniformData = {
time: {
type: 'float',
value: 0.0
},
lacunarity: {
type: 'float',
value: 30.0
},
gain: {
type: 'float',
value: 1.0
},
parallel: {
type: 'b',
value: true
},
light: {
type: 'v2',
value: [0.0, 0.0]
},
dimensions: {
type: 'v2',
value: [800, 400]
},
aspect: {
type: 'float',
value: 1.0
}
};
// 3D gradient Noise
// MIT License
// Copyright © 2013 Inigo Quilez
// https://www.shadertoy.com/view/Xsl3Dl
// Original: https://codepen.io/alaingalvan/pen/gOoEpW
const fragSource = '' +
`precision mediump float;
varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform vec4 filterArea;
uniform vec2 dimensions;
uniform vec2 light;
uniform bool parallel;
uniform float aspect;
uniform float gain;
uniform float lacunarity;
uniform float time;
vec3 hash(vec3 p) {
p = vec3(
dot(p, vec3(127.1, 311.7, 74.7)),
dot(p, vec3(269.5, 183.3, 246.1)),
dot(p, vec3(113.5, 271.9, 124.6))
);
return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);
}
float noise(in vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(
mix(
dot(hash(i + vec3(0.0, 0.0, 0.0)), f - vec3(0.0, 0.0, 0.0)),
dot(hash(i + vec3(1.0, 0.0, 0.0)), f - vec3(1.0, 0.0, 0.0)),
u.x
),
mix(
dot(hash(i + vec3(0.0, 1.0, 0.0)), f - vec3(0.0, 1.0, 0.0)),
dot(hash(i + vec3(1.0, 1.0, 0.0)), f - vec3(1.0, 1.0, 0.0)),
u.x
),
u.y
),
mix(
mix(
dot(hash(i + vec3(0.0, 0.0, 1.0)), f - vec3(0.0, 0.0, 1.0)),
dot(hash(i + vec3(1.0, 0.0, 1.0)), f - vec3(1.0, 0.0, 1.0)),
u.x
),
mix(
dot(hash(i + vec3(0.0, 1.0, 1.0)), f - vec3(0.0, 1.0, 1.0)),
dot(hash(i + vec3(1.0, 1.0, 1.0)), f - vec3(1.0, 1.0, 1.0)),
u.x
),
u.y
),
u.z
);
}
float turb(vec3 pos, float lacunarity, float gain) {
float f, totalGain;
totalGain = gain;
vec3 q = 2.0 * pos;
f = totalGain * noise(q);
q = q * 2.01 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.02 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.03 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.01 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.99 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.98 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
f = 3.0 * f;
return abs(f);
}
void main(void) {
gl_FragColor = texture2D(uSampler, vTextureCoord);
float d = 0.0;
vec2 coord = vTextureCoord;
if (parallel) {
float _cos = light.x;
float _sin = light.y;
d = (_cos * coord.x) + (_sin * coord.y * aspect);
} else {
float dx = coord.x - light.x / dimensions.x;
float dy = (coord.y - light.y / dimensions.y) * aspect;
float dis = sqrt(dx * dx + dy * dy) + 0.00001;
d = dy / dis;
}
vec2 dir = vec2(d, d);
float noise = turb(vec3(dir, 0.0) + vec3(time, 0.0, 62.1 + time) * 0.1, lacunarity, gain);
vec4 mist = vec4(noise, noise, noise, 1.0);
noise = mix(noise, 0.0, 0.3);
mist *= 1.0 - coord.y;
mist = clamp(mist, 0.0, 1.0);
gl_FragColor += mist;
}`;
class Rays extends PIXI.Filter
{
_options = {
angle: 30,
lacunarity: 1.5,
gain: 0.4,
parallel: Math.round(Math.random()),
speed: 0.0003
}
_timeInit = null;
constructor()
{
super(null, fragSource, uniformData);
this._timeInit = Date.now() - Math.floor(Math.random() * 99999999);
}
apply(filterManager, input, output, clearMode, _currentState)
{
this.uniforms.time = (Date.now() - this._timeInit) * this._options.speed;
this.uniforms.lacunarity = this._options.lacunarity;
this.uniforms.gain = this._options.gain;
this.uniforms.parallel = this._options.parallel;
const radians = this._options.angle * Math.PI / 180.0;
this.uniforms.light[0] = Math.cos(radians);
this.uniforms.light[1] = Math.sin(radians);
const {width, height} = input.filterFrame;
this.uniforms.dimensions[0] = width;
this.uniforms.dimensions[1] = height;
this.uniforms.aspect = height / width;
filterManager.applyFilter(this, input, output, clearMode);
}
}
// -------------------------------
class App
{
_app = null;
_resources = null;
constructor() {
this._app = new PIXI.Application({
view: canvas,
width: 800,
height: 600,
transparent: true,
resolution: window.devicePixelRatio
});
this._init();
}
addRelativeFeather(x, y) {
const feather = new PIXI.Sprite(this._resources.feather.texture);
const scale = Math.max(
this._app.screen.width / (feather.width * 3),
this._app.screen.height / (feather.height * 3)
);
feather.scale.set(scale, scale);
feather.position.set(x * feather.width, y * feather.height);
feather.filters = [new Rays()];
this._app.stage.addChild(feather);
}
_main() {
this.addRelativeFeather(0, 0);
this.addRelativeFeather(1, 0);
this.addRelativeFeather(2, 0);
this.addRelativeFeather(0, 1);
this.addRelativeFeather(2, 1);
}
_init() {
const loader = PIXI.Loader.shared;
loader.add({
name: 'feather',
// Icon "feather": https://www.flaticon.com/free-icon/feathers_6981026
url: 'https://cdn-icons-png.flaticon.com/512/6981/6981026.png',
});
loader.onComplete.once((loaderProcessed, resources) => {
this._resources = resources;
this._main();
});
loader.load();
}
}
const app = new App();
* {
margin: 0;
padding: 0;
background: #333;
}
<script src="https://pixijs.download/v6.5.8/pixi.js"></script>
<canvas id="canvas"></canvas>
Is it possible using this filter/shader? Is it correct that the issue is in the color matrix ("float noise(in vec3 p)")?
Also, it's probably the mist = clamp(mist, 0.0, 1.0); where the second parameter might assume the minimum allowed if that makes sense.
Would it be correct to somehow base a pixel color on the source and only increase its "gain" instead?
I would highly appreciate any suggestion since I have already tried various options but it still darkens the origin!
Best and kind regards ✨
const uniformData = {
time: {
type: 'float',
value: 0.0
},
lacunarity: {
type: 'float',
value: 30.0
},
gain: {
type: 'float',
value: 1.0
},
parallel: {
type: 'b',
value: true
},
light: {
type: 'v2',
value: [0.0, 0.0]
},
dimensions: {
type: 'v2',
value: [800, 400]
},
aspect: {
type: 'float',
value: 1.0
}
};
// 3D gradient Noise
// MIT License
// Copyright © 2013 Inigo Quilez
// https://www.shadertoy.com/view/Xsl3Dl
// Original: https://codepen.io/alaingalvan/pen/gOoEpW
const fragSource = '' +
`precision mediump float;
varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform vec4 filterArea;
uniform vec2 dimensions;
uniform vec2 light;
uniform bool parallel;
uniform float aspect;
uniform float gain;
uniform float lacunarity;
uniform float time;
vec3 hash(vec3 p) {
p = vec3(
dot(p, vec3(127.1, 311.7, 74.7)),
dot(p, vec3(269.5, 183.3, 246.1)),
dot(p, vec3(113.5, 271.9, 124.6))
);
return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);
}
float noise(in vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(
mix(
dot(hash(i + vec3(0.0, 0.0, 0.0)), f - vec3(0.0, 0.0, 0.0)),
dot(hash(i + vec3(1.0, 0.0, 0.0)), f - vec3(1.0, 0.0, 0.0)),
u.x
),
mix(
dot(hash(i + vec3(0.0, 1.0, 0.0)), f - vec3(0.0, 1.0, 0.0)),
dot(hash(i + vec3(1.0, 1.0, 0.0)), f - vec3(1.0, 1.0, 0.0)),
u.x
),
u.y
),
mix(
mix(
dot(hash(i + vec3(0.0, 0.0, 1.0)), f - vec3(0.0, 0.0, 1.0)),
dot(hash(i + vec3(1.0, 0.0, 1.0)), f - vec3(1.0, 0.0, 1.0)),
u.x
),
mix(
dot(hash(i + vec3(0.0, 1.0, 1.0)), f - vec3(0.0, 1.0, 1.0)),
dot(hash(i + vec3(1.0, 1.0, 1.0)), f - vec3(1.0, 1.0, 1.0)),
u.x
),
u.y
),
u.z
);
}
float turb(vec3 pos, float lacunarity, float gain) {
float f, totalGain;
totalGain = gain;
vec3 q = 2.0 * pos;
f = totalGain * noise(q);
q = q * 2.01 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.02 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.03 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.01 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.99 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.98 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
f = 3.0 * f;
return abs(f);
}
void main(void) {
gl_FragColor = texture2D(uSampler, vTextureCoord);
float d = 0.0;
vec2 coord = vTextureCoord;
if (parallel) {
float _cos = light.x;
float _sin = light.y;
d = (_cos * coord.x) + (_sin * coord.y * aspect);
} else {
float dx = coord.x - light.x / dimensions.x;
float dy = (coord.y - light.y / dimensions.y) * aspect;
float dis = sqrt(dx * dx + dy * dy) + 0.00001;
d = dy / dis;
}
vec2 dir = vec2(d, d);
float noise = turb(vec3(dir, 0.0) + vec3(time, 0.0, 62.1 + time) * 0.1, lacunarity, gain);
vec4 mist = vec4(noise, noise, noise, noise);
noise = mix(noise, 0.0, 0.3);
mist *= 1.0 - coord.y;
mist = clamp(mist, 0.0, 1.0);
gl_FragColor += mist;
}`;
class Rays extends PIXI.Filter
{
_options = {
angle: 30,
lacunarity: 1.5,
gain: 0.4,
parallel: Math.round(Math.random()),
speed: 0.0003
}
_timeInit = null;
constructor()
{
super(null, fragSource, uniformData);
this._timeInit = Date.now() - Math.floor(Math.random() * 99999999);
}
apply(filterManager, input, output, clearMode, _currentState)
{
this.uniforms.time = (Date.now() - this._timeInit) * this._options.speed;
this.uniforms.lacunarity = this._options.lacunarity;
this.uniforms.gain = this._options.gain;
this.uniforms.parallel = this._options.parallel;
const radians = this._options.angle * Math.PI / 180.0;
this.uniforms.light[0] = Math.cos(radians);
this.uniforms.light[1] = Math.sin(radians);
const {width, height} = input.filterFrame;
this.uniforms.dimensions[0] = width;
this.uniforms.dimensions[1] = height;
this.uniforms.aspect = height / width;
filterManager.applyFilter(this, input, output, clearMode);
}
}
// -------------------------------
class App
{
_app = null;
_resources = null;
constructor() {
this._app = new PIXI.Application({
view: canvas,
width: 800,
height: 600,
transparent: true,
resolution: window.devicePixelRatio
});
this._init();
}
addRelativeFeather(x, y) {
const feather = new PIXI.Sprite(this._resources.feather.texture);
const scale = Math.max(
this._app.screen.width / (feather.width * 3),
this._app.screen.height / (feather.height * 3)
);
feather.scale.set(scale, scale);
feather.position.set(x * feather.width, y * feather.height);
feather.filters = [new Rays()];
this._app.stage.addChild(feather);
}
_main() {
this.addRelativeFeather(0, 0);
this.addRelativeFeather(1, 0);
this.addRelativeFeather(2, 0);
this.addRelativeFeather(0, 1);
this.addRelativeFeather(2, 1);
}
_init() {
const loader = PIXI.Loader.shared;
loader.add({
name: 'feather',
// Icon "feather": https://www.flaticon.com/free-icon/feathers_6981026
url: 'https://cdn-icons-png.flaticon.com/512/6981/6981026.png',
});
loader.onComplete.once((loaderProcessed, resources) => {
this._resources = resources;
this._main();
});
loader.load();
}
}
const app = new App();
* {
margin: 0;
padding: 0;
background: #333;
}
<script src="https://pixijs.download/v6.5.8/pixi.js"></script>
<canvas id="canvas"></canvas>
The shader defines the following vec4 for painting with hardcoded 1.0 alpha:
vec4 mist = vec4(noise, noise, noise, 1.0);
Use the whiteness of the noise value as alpha as following to get rid of the black background:
vec4 mist = vec4(noise, noise, noise, noise);
I have been studying the Metal API (newbie here) and working with the examples and documentation to create a 3D animation in my iOS app. I know I can use SceneKit but for the moment I want to understand and learn how Metal API works.
One of the examples from Apple implements a decent number of textures mapping for the object, but the emission texture is missing. After a bit of study I came with a solution like this:
float3 computeDiffuse(LightingParameters parameters)
{
float3 diffuseRawValue = float3(((1.0/PI) * parameters.baseColor) * (1.0 - parameters.metalness));
return diffuseRawValue * parameters.nDotl * parameters.ambientOcclusion;
}
float3 computeSpecular(LightingParameters parameters)
{
float specularRoughness = parameters.roughness * (1.0 - parameters.metalness) + parameters.metalness;
float Ds = Distribution(parameters.nDoth, specularRoughness);
float3 Cspec0 = float3(1.0f);
float3 Fs = float3(mix(float3(Cspec0), float3(1), Fresnel(parameters.hDotl)));
float alphaG = sqr(specularRoughness * 0.5 + 0.5);
float Gs = Geometry(parameters.nDotl, alphaG) * Geometry(parameters.nDotv, alphaG);
float3 specularOutput = (Ds * Gs * Fs * parameters.irradiatedColor)
* (1.0 + parameters.metalness * float3(parameters.baseColor))
+ float3(parameters.metalness)
* parameters.irradiatedColor
* float3(parameters.baseColor);
return specularOutput * parameters.ambientOcclusion;
}
float3 computeEmissive(LightingParameters parameters)
{
float3 diffuseRawValue = float3(((1.0/PI) * parameters.emissiveColor));
return diffuseRawValue;
}
//...
fragment float4
fragmentLighting(ColorInOut in [[stage_in]],
constant AAPLUniforms & uniforms [[ buffer(AAPLBufferIndexUniforms) ]],
constant AAPLMaterialUniforms & materialUniforms [[ buffer(AAPLBufferIndexMaterialUniforms) ]],
texture2d<float> baseColorMap [[ texture(AAPLTextureIndexBaseColor), function_constant(has_base_color_map) ]],
texture2d<float> normalMap [[ texture(AAPLTextureIndexNormal), function_constant(has_normal_map) ]],
texture2d<float> metallicMap [[ texture(AAPLTextureIndexMetallic), function_constant(has_metallic_map) ]],
texture2d<float> roughnessMap [[ texture(AAPLTextureIndexRoughness), function_constant(has_roughness_map) ]],
texture2d<float> ambientOcclusionMap [[ texture(AAPLTextureIndexAmbientOcclusion), function_constant(has_ambient_occlusion_map) ]],
texture2d<float> emissiveMap [[ texture(AAPLTextureIndexEmissive), function_constant(has_emissive_map) ]],
texturecube<float> irradianceMap [[ texture(AAPLTextureIndexIrradianceMap), function_constant(has_irradiance_map)]])
{
float4 final_color = float4(0);
LightingParameters parameters = calculateParameters(in,
uniforms,
materialUniforms,
baseColorMap,
normalMap,
metallicMap,
roughnessMap,
ambientOcclusionMap,
emissiveMap,
irradianceMap);
final_color = float4(computeSpecular(parameters) + computeDiffuse(parameters) + computeEmissive(parameters), 1.0f);
return final_color;
}
This code above makes the object get slightly white, which is not the desired effect.
Note the line computeSpecular(parameters) + computeDiffuse(parameters) + computeEmissive(parameters), in the original source code computeEmissive(parameters) does not exist, that's something that I have implemented trying to make the color more intense, probably this is totally wrong and what I have should be doing is to change the contrast, brightness and luminance, but I am not sure how to do this.
I am probably doing everything wrong, I am open to any suggestion. :)
Thank you.
I am learning GLSL through Unity and I recently came across a problem involving the storing of variables.
Shader "Shader" {
Properties{
_Hole_Position("hole_Position", Vector) = (0., 0., 0., 1.0)
_Hole_EventHorizonDistance("hole_EventHorizonDistance", Float) = 1.0
_DebugValue("debugValue", Float) = 0.0
}
SubShader{
Pass{
GLSLPROGRAM
uniform mat4 _Object2World;
//Variables
varying float debugValue;
varying vec4 pos;
varying vec4 hole_Position;
varying float hole_EventHorizonDistance = 1;
#ifdef VERTEX
void main()
{
pos = _Object2World * gl_Vertex;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#endif
#ifdef FRAGMENT
void main()
{
float dist = distance(vec4(pos.x, 0.0,pos.z, 1.0), vec4(hole_Position.x, 0.0, hole_Position.z, 1.0));
debugValue = dist;
if (dist < hole_EventHorizonDistance)
{
gl_FragColor = vec4(0.3, 0.3, 0.3, 1.0);
}
else
{
gl_FragColor = vec4(0.4, 0.6, 1.0, 1.0);
}
//gl_FragColor = vec4(hole_EventHorizonDistance, 0, 0, 1.0);
}
#endif
ENDGLSL
}
}
}
Now Hole_Position and EventHorizonDistance are changed from an outside C#-script with:
g.GetComponent<Renderer>().sharedMaterial.SetVector("_Hole_Position", new Vector4(transform.position.x, transform.position.y, transform.position.z, 1));
g.GetComponent<Renderer>().sharedMaterial.SetFloat("_Hole_EventHorizonDistance", 2);
this does not work as I intend it too (by changing the fragments color if its position is within 2 units from Hole_Position. However debugging with:
gl_FragColor = vec4(hole_EventHorizonDistance, 0, 0, 1.0);
seemingly suggests that EventHorizon is 0 at all times (the mesh tested on remains completely black), however debugging by getting and printing the variable from an outside (via
print(g.GetComponent<Renderer>().sharedMaterial.GetFloat("_Hole_EventHorizonDistance"));
) tells me EventHorizonDistance = 2. I cannot wrap my head around why this is the case, why is it so?
I am trying to run a model in OpenBUGS. But I am getting an error "Variable TT is not defined". Here is my BUGS code:
model{
for(t in 2:TT){
for(i in 1:N){
y[t,i] ~ dmnorm(y1[t,i], tau[i])
}
y1[t,1] <- (p[1,1] * y[t-1,1]) + (p[1,2] *y[t-1,2]) + (p[1,3] *y[t-1,3])
y1[t,2] <- (p[2,1] * y[t-1,1]) + (p[2,2] *y[t-1,2]) + (p[2,3] *y[t-1,3])
y1[t,3] <- (p[3,1] * y[t-1,1]) + (p[3,2] *y[t-1,2]) + (p[3,3] *y[t-1,3])
}
for (s1 in 1:N) {
for (s2 in 1:N) {
p[s1, s2]~ dnorm(1, 1)
}
}
for(i in 1:N){
tau[i] ~ dgamma(0.001, 0.001)
}
}
Here is my data and R code to run the BUGS code:
Data=structure(.Data=c(0.1, 0.2, 0.5, 0.2, 0.2, 0.8, 0.2, 0.4, 0.3, 0.2, 0.1, 0.6, 0.1, 0.5, 0.6), .Dim=c(5,3))
TT=nrow(Data)
N=ncol(Data)
y=as.matrix(Data)
sp.data = list(y, N, TT)
Sp.sim0<- bugs (sp.data, inits=NULL,
parameters=c('p'), model.file= "model2.txt",n.chains=2, DIC=TRUE,n.iter=1000, codaPkg=FALSE,debug=TRUE)
Can any please help to t solve this problem? Thanks in advance.
I'm trying to get a proper setup for 3D programs, and the next step is a texture loader. I am trying to use DevIL, but I can't seem to get it working, and no explanatory text seems to be up to date.
To start with, I'm just going to include a dump of my project: (Keep in mind that it just happens to be in this state, it's not all relevant; Also note that 'IOUtil.cpp' just defines 'Print', which prints to 'cout'. It didn't seem relevant, so I excluded it.)
Project Structure:
+- bin
+- include
| +- GLFW
| | +- glfw3.h
| | +- glfw3native.h
| +- IL
| | +- config.h
| | +- config.h.win
| | +- devil_internal_exports.h
| | +- il.h
| | +- il_wrap.h
| | +- ilu.h
| | +- ilu_region.h
| | +- ilut.h
| | +- ilut_config.h
+- lib
| +- unicode
| | +- DevIL.dll
| | +- DevIL.lib
| | +- ILU.dll
| | +- ILU.lib
| | +- ILUT.dll
| | +- ILUT.lib
| +- DevIL.dll
| +- DevIL.lib
| +- ILU.dll
| +- ILU.lib
| +- ILUT.dll
| +- ILUT.lib
| +- libglfw3dll.a
+- logs
+- src
| +- Main.exe
+- build.bat
+- run.bat
Main.exe:
#include <GLFW/glfw3.h>
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
#include <stdlib.h>
#include <algorithm>
#include "util/IOUtil.cpp"
float SENSITIVITY = 0.25;
float cursorX = 0;
float cursorY = 0;
float camX = 0;
float camY = 0;
static void error_callback(int error, const char* description) {
Print("GLFW ERROR: " + (std::string)description);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, GL_TRUE);
}
}
static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos) {
float dx = xpos - cursorX;
float dy = -ypos - cursorY;
cursorX = xpos;
cursorY = -ypos;
camX += dx * SENSITIVITY;
camY += dy * SENSITIVITY;
if (camX < 0) {
camX += 360;
}
if (camX > 360) {
camX -= 360;
}
camY = std::max(-90.0f, std::min(90.0f, camY));
}
int main(void) {
glfwSetErrorCallback(error_callback); //Set the error callback
Print("Initializing GLFW");
if (!glfwInit()) { //If initialization fails, crash
Print("GLFW initialization failed!");
exit(EXIT_FAILURE);
}
Print("Initializing window");
GLFWwindow* window = glfwCreateWindow(600, 600, "FPS", NULL, NULL); //Initialize the window
if (!window) { //If window initialization fails, crash
Print("Window initialization failed!");
glfwTerminate(); //Deinitialize
exit(EXIT_FAILURE);
}
ilutRenderer(ILUT_OPENGL); //Bind Texture Loader to Renderer
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); //Capture the cursor
glfwMakeContextCurrent(window); //Create the context
glfwSwapInterval(1); //Set the swap interval
glfwSetKeyCallback(window, key_callback); //Set the key callback
glfwSetCursorPosCallback(window, cursor_position_callback); //Set the cursor callback
//ilInit();
//ILuint image;
//ilGenImages(1, &image);
//ilBindImage(image);
//ilLoadImage("data/image.png");
glEnable(GL_TEXTURE_2D);
GLuint tex;
//tex = ilutGLBindTexImage();
Print("Beginning main loop");
while (!glfwWindowShouldClose(window)) { //Main loop, ends when window close is requested
float ratio;
int width, height;
glfwGetFramebufferSize(window, &width, &height); //Load the window dimensions
ratio = width / (float) height; //Calculate the aspect ratio
glViewport(0, 0, width, height); //Configure the viewport
glClear(GL_COLOR_BUFFER_BIT); //Clear the buffer
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float near = 1; //Near Clipping Plane
float far = 1000; //Far Clipping Plane
float fov = 1; //tan(fovAngle)/2.
glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Enable depth testing
//glEnable(GL_DEPTH_TEST);
//Set background color
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glPushMatrix();
glRotatef(camY, -1.0, 0.0, 0.0);
glRotatef(camX, 0.0, 1.0, 0.0);
//glTranslatef(0,0,-10);
glBegin(GL_QUADS);
//glColor3f(1.0, 0.0, 0.0);
glVertex3f(-1.0, -1.0, -10.0);
//glColor3f(1.0, 0.0, 1.0);
glVertex3f(-1.0, 1.0, -10.0);
//glColor3f(1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, -10.0);
//glColor3f(1.0, 1.0, 0.0);
glVertex3f(1.0, -1.0, -10.0);
glEnd();
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-1.0, -1.0, 10.0);
glColor3f(1.0, 0.0, 1.0);
glVertex3f(-1.0, 1.0, 10.0);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 10.0);
glColor3f(1.0, 1.0, 0.0);
glVertex3f(1.0, -1.0, 10.0);
glEnd();
glPopMatrix();
glfwSwapBuffers(window); //Swap buffers
glfwPollEvents(); //Poll events
}
Print("Window close requested");
glfwDestroyWindow(window); //Close the window
Print("Deinitializing");
glfwTerminate(); //Deinitialize
exit(EXIT_SUCCESS); //End the program
}
build.bat:
g++ -c -v -Iinclude src/Main.cpp 2>logs/build.txt
g++ -v -o bin/main Main.o -Llib -lglfw3dll -lopengl32 -lgdi32 -lDevIL -lILU -lILUT 2>logs/link.txt
del Main.o
pause
Here is the log from line one of the batch file:
Using built-in specs.
COLLECT_GCC=g++
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-c' '-v' '-I' 'include' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro'
c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1plus.exe -quiet -v -I include -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.8.1/ src/Main.cpp -quiet -dumpbase Main.cpp -mtune=generic -march=pentiumpro -auxbase Main -version -o C:\Users\MyUsername\AppData\Local\Temp\cccPMwk6.s
GNU C++ (GCC) version 4.8.1 (mingw32)
compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
warning: MPC header version 1.0.1 differs from library version 1.0.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../include"
ignoring duplicate directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include-fixed"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++/mingw32
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++/backward
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include-fixed
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../mingw32/include
End of search list.
GNU C++ (GCC) version 4.8.1 (mingw32)
compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
warning: MPC header version 1.0.1 differs from library version 1.0.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 1ebc2a6f92fbd3aadc367a20a63fdf9f
src/Main.cpp: In function 'int main()':
src/Main.cpp:95:14: error: expected unqualified-id before '=' token
float near = 1; //Near Clipping Plane
^
src/Main.cpp:96:13: error: expected unqualified-id before '=' token
float far = 1000; //Far Clipping Plane
^
src/Main.cpp:98:29: error: invalid type argument of unary '*' (have 'float')
glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
^
src/Main.cpp:98:49: error: invalid type argument of unary '*' (have 'float')
glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
^
src/Main.cpp:98:69: error: expected primary-expression before ',' token
glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
^
src/Main.cpp:98:74: error: expected primary-expression before ')' token
glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
^
Sorry for just dumping everything, but I don't know what else to do. I don't see why the IL includes would cause syntax errors in syntactically correct code.
Anyone know what's going wrong?
As it turns out, the issue was being caused by the names of the variables, which I realized when I noticed that 'fov' was not affected. Changing 'near' and 'far' to 'near_plane' and 'far_plane' (along with all references) fixed the issue.
Out of interest, what do 'near' and 'far' define in DevIL?