How can I optimize this code
void inittexture(void)
{
char* texture = new char[1024 * 1024 * 3];
HDC hdc;
hdc = GetDC(NULL);
for (int y = 0; y < screenheight; y++)
for (int x = 0; x < screenwidth; x++)
{
COLORREF c = GetPixel(hdc, x, y);
texture[y * 1024 * 3 + x * 3] = GetRValue(c);
texture[y * 1024 * 3 + x * 3 + 1] = GetGValue(c);
texture[y * 1024 * 3 + x * 3 + 2] = GetBValue(c);
}
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &screentexture);
glBindTexture(GL_TEXTURE_2D, screentexture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 1024, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, texture);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
delete[] texture;
}