Hello, I am currently implementing Connway’s game of life using cuda OpenGL. I am using texture memory to store the data of the current game All was fine until I had to draw the generations on the screen. The result of the screen is wrong/ distored unless the screen width and height have the same dimension as the game world.
The size of my world is 512 * 512 and the size of the screen is 1024 * 768;
Nvm, i solved it, simple error on my part, since i am writing to 2 buffers, i need to 2 set of indexes to access each buffer, in the original i only used 1 so hence the distortion it drew
My kernel code:
__global__ void GenerateGameWorld(char* nextGame , uchar4* deviceGameData, int worldWidth, int worldHeight , int screenWidth, int screenHeight, int dx, int dy, double zoom)
{
int y = blockDim.y * blockIdx.y + threadIdx.y;
int x = blockDim.x * blockIdx.x + threadIdx.x;
// I want it to draw in cycles if the screen is bigger then the game world
int cx = x % worldWidth;
int cy = y % worldHeight ;
int gameId = cy * worldWidth + x;
int id = y * screenWidth + x;
// fetching of data from game world...
if (sumOfNeighbours == 2)
{
nextGame [gameId] = Data ;
unsigned char yColour = (Data ) ? 255 : 0;
deviceGameData[id].x = 0;
deviceGameData[id].y = yColour;
deviceGameData[id].z = 0;
}
else if (sumOfNeighbours == 3)
{
nextGame [gameId] = 1;
deviceGameData[id].x = 0;
deviceGameData[id].y = 255;
deviceGameData[id].z = 0;
}
else
{
nextGame [gameId] = 0;
deviceGameData[id].x = 0;
deviceGameData[id].y = 0;
deviceGameData[id].z = 0;
}
}