I have the following code. This blasts 32-bit pixels to the screen using an array. The array is processed by the CPU, rather than the graphics card, so I hear doing this via a texture would be faster in the long run. How can I move the array to an accelated texture?
UCHAR buffer32[SCREEN_WIDTH * SCREEN_HEIGHT * 4];
void plotPixel32(int x, int y, int r, int g, int b, int a = 255)
{
buffer32[4 * (y * SCREEN_WIDTH + x) + 0] = r;
buffer32[4 * (y * SCREEN_WIDTH + x) + 1] = g;
buffer32[4 * (y * SCREEN_WIDTH + x) + 2] = b;
buffer32[4 * (y * SCREEN_WIDTH + x) + 3] = a;
}
void Game_Render()
{
gl.clear();
for (int i = 0; i < 5000; i++)
plotPixel32(rand()%SCREEN_WIDTH, rand()%SCREEN_HEIGHT, rand()%256, rand()%256, rand()%256);
// raster it
glRasterPos2f(0, 1); // raster at the top-left screen
glPixelZoom( 1, -1 );
glDrawPixels(SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, buffer32);
gl.present();
}