This is a tough question to explain.
I am using SDL, Opengl and opencl.
I have a simple window that is rendering a quad over the full screen and am changing its texture each frame.
I am running the simple kernel below which is supposed to paint the screen with a nice sky blue gradient. It works, until i move the mouse or hit a key. It is the strangest thing. When i push a key or move the mouse, the colors change. It goes from blue to purple to black to pink and so on. I have implemented no key input code and none of my drawing code is linked in any way to key presses so i have no idea.
I know this might be tough to answer without seeing my full code. The only thing i can think of is that i dont know enough about opencl so maybe my kernel below is using some kind of system defined variable like U and V and that is causing it??
Or maybe its an sdl thing but my code is super simple, literally just a copy and paste from an sdl tutorial that sets up an opengl window.
Any help would be greatly appreciated!
Thanks
struct Sphere{ float3 pos; float radius;};struct Ray{ float3 origin; float3 dir;};float3 Colour(struct Ray *ray){ //lerp float3 unit_direction = normalize(ray->dir); float d = 0.5*(unit_direction.y + 1.0); float3 ones = (float3)(1.0,1.0,1.0); float3 blue = (float3)(0.5,0.7,1.0); float3 tempa = ones * (1.0 - d); float3 tempb = blue *d; return (tempa + tempb);}__kernel void __main(__global float4* data, uint width, uint height) { struct Sphere ball; ball.pos = (float3)(0,0,-1); ball.radius = 1.0f; struct Ray ray; ray.origin = (float3)(0,0,0); float u, v; int id = get_global_id(0); float3 lowerLeft = (float3)(-2.0, -2.0, -1.0); float3 horizontal = (float3)(4.0, 0.0, 0.0); float3 vertical = (float3)(0.0, 4.0, 0.0); float x = (float)(get_global_id(0) % width) / (float)(width); float y = (float)(get_global_id(0) / width) / (float)(height); float aspect = (float)(width) / (float)(height); x = (x -0.5f)*aspect; y = y -0.5f; u = x / (float)width; v = y / (float)height; float3 U, V, COMB; U = horizontal*u; V = vertical*v; COMB = U+V; ray.dir = normalize(lowerLeft+COMB); float3 colour = Colour(&ray); //data[get_global_id(0)] = (float4)(0.5,0.5,0.5,1); //data[get_global_id(0)] += (float4)(0.5,0.5,0,0); data[get_global_id(0)] += (float4)(colour.x,colour.y,colour.z,1.0f);}