Simple Opengl interop


I’m using oclSimpleGL code from nvidia SDK, and I’m triying to write the same function for host to compare performances,

so this is the host function I wrote

[codebox]extern “C” void sine_waveHost( float* pos, unsigned int width, unsigned int height, float time)


//unsigned int x = get_global_id(0);

//unsigned int y = get_global_id(1);

for(unsigned int y = 0; y < height; y++)			// local section of rows


	for(unsigned int x = 0; x < width; x++)		// all the columns


		// calculate uv coordinates

		float u = x / (float) width;

		float v = y / (float) height;

		u = u*2.0f - 1.0f;

		v = v*2.0f - 1.0f;

		// calculate simple sine wave pattern

		float freq = 4.0f;

		float w = sin(u*freq + time) * cos(v*freq + time) * 0.5f;

		// write output vertex

		pos[y*width+x] = (float)(u, w, v, 1.0f);




I call this function in my main program, and I made a switch key to switch from cpu to gpu,

just like it’s done in the other examples in SDK,

my question is how to initialise my pos argument in my main, when I write float* pos =0; then I call the function I got null pointer

and is my code alright?


You declared “pos” as a pointer of float. If you want to initialize a value for “pos” you must first allocate memory for it before assigning a value to its memory location, as the following:

float * pos;

pos = (float *)malloc(sizeof(float));

*pos = 0.0;