OpenGL directly on the desktop
-
I'm trying to add visual effects to the desktop. I want to be able to use the desktop as normal at the same time. This is what I have been coding so far. But the triangle is never painted to the screen.
#include #include int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { HDC hDC; HGLRC hRC; float theta = 0.0f; PIXELFORMATDESCRIPTOR pfd; int format; // get the device context for the whole screen instead of a window hDC = GetWindowDC(NULL); // set the pixel format for the DC ZeroMemory( &pfd, sizeof( pfd ) ); pfd.nSize = sizeof( pfd ); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 16; pfd.iLayerType = PFD_MAIN_PLANE; format = ChoosePixelFormat( hDC, &pfd ); SetPixelFormat( hDC, format, &pfd ); // create and enable the render context (RC) hRC = wglCreateContext( hDC ); wglMakeCurrent( hDC, hRC ); while ( true ) { glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClear( GL_COLOR_BUFFER_BIT ); glPushMatrix(); glRotatef( theta, 0.0f, 0.0f, 1.0f ); glBegin( GL_TRIANGLES ); glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f ); glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f ); glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f ); glEnd(); glPopMatrix(); SwapBuffers( hDC ); theta += 1.0f; } return 0; }
Have anyone done something like this before? -
I'm trying to add visual effects to the desktop. I want to be able to use the desktop as normal at the same time. This is what I have been coding so far. But the triangle is never painted to the screen.
#include #include int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { HDC hDC; HGLRC hRC; float theta = 0.0f; PIXELFORMATDESCRIPTOR pfd; int format; // get the device context for the whole screen instead of a window hDC = GetWindowDC(NULL); // set the pixel format for the DC ZeroMemory( &pfd, sizeof( pfd ) ); pfd.nSize = sizeof( pfd ); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 16; pfd.iLayerType = PFD_MAIN_PLANE; format = ChoosePixelFormat( hDC, &pfd ); SetPixelFormat( hDC, format, &pfd ); // create and enable the render context (RC) hRC = wglCreateContext( hDC ); wglMakeCurrent( hDC, hRC ); while ( true ) { glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClear( GL_COLOR_BUFFER_BIT ); glPushMatrix(); glRotatef( theta, 0.0f, 0.0f, 1.0f ); glBegin( GL_TRIANGLES ); glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f ); glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f ); glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f ); glEnd(); glPopMatrix(); SwapBuffers( hDC ); theta += 1.0f; } return 0; }
Have anyone done something like this before?Firstly, what do the
#include
s actually include. I assume they are unimportant and have either been left out or forgotten. But more to the point, you should have a look atPFD_DRAW_TO_WINDOW
in the variablepfd.dwFlags
. I too am using OpenGL for a small project I am making. I don't know that much about it but i think you might have to set it to draw to theDESKTOP
. I think the desktop is just a special kind of window. What you are trying to do sounds interesting. Let me know when you have it working-------------------------------- Customer in computer shop: "Can you copy the Internet onto this disk for me?"