有没有办法用OpenGL更改光标? 我在Windows 7上使用Dev C ++。 这是我当前尝试更改光标的代码:
#include "Load.h" // Load.h
int main() // int main()
{
HINSTANCE hInstance = 0; // Creating Window, Just Skip to Middle
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "GLSample";
RegisterClass (&wc);
hWnd = CreateWindow (
"GLSample", "Cursor",
WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 1280, 680,
NULL, NULL, hInstance, NULL);
EnableOpenGL (hWnd, &hDC, &hRC);
while (!bQuit)
{
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
else
{
/////////////////////////////////////////////////////////////////////////////////////
POINT p;
if(GetCursorPos(&p))
{
Image_Ignore(hDC, "Cursor", p.x, p.y, 1340, 678, 255, 255, 255);
}
///////////////////////////////////////////////////////////////////////////////////////
}
}
DisableOpenGL (hWnd, hDC, hRC);
DestroyWindow (hWnd); // Shutting down Window
return msg.wParam;
}
Load.h:
#include <windows.h> // Includes
#include <gl/gl.h>
#include <iostream>
#include "bitmap_image.h"
using namespace std;
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, // Start of OpenGL Functions... (Skip until end)
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitMessage (0);
return 0;
case WM_DESTROY:
return 0;
case WM_KEYDOWN:
switch (wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
}
return 0;
default:
return DefWindowProc (hWnd, message, wParam, lParam);
}
}
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
*hDC = GetDC (hWnd);
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;
iFormat = ChoosePixelFormat (*hDC, &pfd);
SetPixelFormat (*hDC, iFormat, &pfd);
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );
}
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent (NULL, NULL);
wglDeleteContext (hRC);
ReleaseDC (hWnd, hDC);
} // End of OpenGL Functions...
void Image_Ignore(HDC hDC, string File_Name, int x_position, int y_position, int length, int height, int re, int ge, int be)
{
File_Name = "C:/Users/David/Pictures/" + File_Name + ".bmp";
bitmap_image image(File_Name); // Open the bitmap
unsigned char red;
unsigned char green;
unsigned char blue;
restart:
image.get_pixel(x_position, y_position, red, green, blue); // Get the red green and blue from x_position and y_position and store it in red green and blue.
if(red==re)
{
if(green==ge)
{
if(blue==be)
{
goto after;
}
}
}
glBegin (GL_TRIANGLES); // Make a pixel at x_position and y_position with red green and blue.
glColor3ub (red, green, blue);
glVertex2f (-1 + 0.0015 * x_position, 1 - 0.003 * y_position);
glVertex2f (-1 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 1 - 0.003 * y_position);
glEnd();
glBegin (GL_TRIANGLES);
glColor3ub (red, green, blue);
glVertex2f (-1 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 1 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glEnd();
after:
if (x_position==length) // If x_position equals to length of bmp set x_position to 0 and add 1 to y_position.
{
if (y_position==height) // If bmp is done loading go to done.
{
goto done;
}
x_position = 0;
y_position = y_position + 1;
}
x_position = x_position + 1;
goto restart;
done:
SwapBuffers(hDC); // Put it on the screen
}
的bitmap_image.h