我下载的ebook无法打开

2025-12-15 22:19:41
推荐回答(1个)
回答1:

重装,或是换个EBOOK软件,不知道你明不明白计算机语言,你也可以用记事本修改:
//SDK代码如下
//---------------------------------------------------------------------------
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")

#include
#include
#include
#include
#include

#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define SCREEN_DEPTH 16

bool g_bFullScreen = TRUE;
HWND g_hWnd;
RECT g_rRect;
HDC g_hDC;
HGLRC g_hRC;
HINSTANCE g_hInstance;
int mouse_x=0,mouse_y=0;

LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

void RenderScene();

HWND CreateMyWindow(LPSTR strWindowName, int width, int height, DWORD dwStyle, HINSTANCE hInstance)
{
HWND hWnd;
WNDCLASS wndclass;

memset(&wndclass, 0, sizeof(WNDCLASS));
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WinProc;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wndclass.lpszClassName = "test";

RegisterClass(&wndclass);

dwStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

if(dwStyle)
{
dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
}

g_hInstance = hInstance;

RECT rWindow;
rWindow.left = 0;
rWindow.right = width;
rWindow.top = 0;
rWindow.bottom = height;

AdjustWindowRect( &rWindow, dwStyle, false);

hWnd = CreateWindow("test", strWindowName, dwStyle, 0, 0,
rWindow.right - rWindow.left, rWindow.bottom - rWindow.top,
NULL, NULL, hInstance, NULL);

if(!hWnd) return NULL;
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

SetFocus(hWnd);

return hWnd;
}
//
//
//
WPARAM MainLoop()
{
MSG msg;

while(1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
RenderScene();
}
}

return(msg.wParam);
}
//
//
//
bool bSetupPixelFormat(HDC hdc)
{
PIXELFORMATDESCRIPTOR pfd = {0};
int pixelformat;
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.dwLayerMask = PFD_MAIN_PLANE;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = SCREEN_DEPTH;
pfd.cDepthBits = SCREEN_DEPTH;
pfd.cAccumBits = 0;
pfd.cStencilBits = 0;
if ( (pixelformat = ChoosePixelFormat(hdc, &pfd)) == FALSE )
{
MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
return FALSE;
}
if (SetPixelFormat(hdc, pixelformat, &pfd) == FALSE)
{
MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
return FALSE;
}
return TRUE;
}
//
//
//
void SizeOpenGLScreen(int width, int height)
{
if (height==0)
{
height=1;
}
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height, 1 ,150.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//
//
//
void InitializeOpenGL(int width, int height)
{
g_hDC = GetDC(g_hWnd);
if (!bSetupPixelFormat(g_hDC))
PostQuitMessage (0);
g_hRC = wglCreateContext(g_hDC);
wglMakeCurrent(g_hDC, g_hRC);
SizeOpenGLScreen(width, height);
}
//
//
//
void Init(HWND hWnd)
{
g_hWnd = hWnd;
GetClientRect(g_hWnd, &g_rRect);
InitializeOpenGL(g_rRect.right, g_rRect.bottom);
}
//
//
//
void RenderScene()
{
int i=0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0, 0, 6, 0, 0, 0, 0, 1, 0);
glBegin (GL_TRIANGLES);
glVertex3f(0, 1, 0);
glVertex3f(-1, 0, 0); glVertex3f(1, 0, 0);
glEnd();
SwapBuffers(g_hDC);
}
//
//
//
void DeInit()
{
if (g_hRC)
{
wglMakeCurrent(NULL, NULL);
wglDeleteContext(g_hRC);
}

if (g_hDC)
ReleaseDC(g_hWnd, g_hDC);

if(g_bFullScreen)
{
ChangeDisplaySettings(NULL,0);
ShowCursor(TRUE);
}

UnregisterClass("test", g_hInstance);

PostQuitMessage (0);
}

WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd = CreateMyWindow("test", SCREEN_WIDTH, SCREEN_HEIGHT, 0, hInstance);

if(hWnd == NULL) return TRUE;

Init(hWnd);

return MainLoop();
}
//
//
//
void Selection()
{
GLuint buffer[512];
GLint hits;
GLint viewport[4];

glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(512, buffer);

(void) glRenderMode(GL_SELECT);

glInitNames();
glPushName(0);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

gluPickMatrix((GLdouble) mouse_x, (GLdouble) (viewport[3]-mouse_y), 1.0f, 1.0f, viewport);

gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);

{
glLoadIdentity();
glTranslatef(0.0f,0.0f,-6.0f);
glLoadName(1);
glPushMatrix();
//设置断点
glBegin (GL_TRIANGLES);
glVertex3f(0, 1, 0);
glVertex3f(-1, 0, 0);
glVertex3f(1, 0, 0);
glEnd();
glPopMatrix();
}

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
hits=glRenderMode(GL_RENDER);
if (hits ==1)
{
MessageBox(g_hWnd, "选中了三角形","",0);
}

}
//
//
//
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LONG lRet = 0;
PAINTSTRUCT ps;

switch (uMsg)
{
case WM_SIZE:
if(!g_bFullScreen)
{
SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));
GetClientRect(hWnd, &g_rRect);
}
break;

case WM_PAINT:
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;

case WM_KEYDOWN:
if(wParam == VK_ESCAPE) DeInit();
break;
case WM_LBUTTONDOWN:
mouse_x = LOWORD(lParam);
mouse_y = HIWORD(lParam);
Selection();
break;
case WM_MOUSEMOVE:
mouse_x = LOWORD(lParam);
mouse_y = HIWORD(lParam);
break;
case WM_DESTROY:
DeInit();
break;

default:
lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
break;
}

return lRet;
}

肯定是BCB的openGL库的问题,我用BCB2006编译运行,没问题