#include <windows.h>
#include <stdio.h>
#include <gl/glut.h>
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
//BOOL CreateWindow(int width,int height);
HINSTANCE hInstance;
void init(void)
{
glClearColor(0.0f,0.0f,0.0f,0.0f);
glShadeModel(GL_FLAT);
}
void display(void)
{
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,1.0f,1.0f);
glPushMatrix();
glutSolidSphere(1.0f,40,16);
glPopMatrix();
}
void reshape(int w,int h)
{
glViewport(0.0f,0.0f,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f,(GLsizei)w / (GLsizei)h,1.0f,20.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
BOOL CreateWindowGL(int width,int height)
{
// hInstance = GetModuleHandle(NULL);
hInstance = GetModuleHandle(NULL);
int right,bottom;
right = width;
bottom = height;
HWND hwnd;
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor = LoadCursor(NULL,IDC_CROSS);
wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = "lidecheng";
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
if(!RegisterClass(&wc))
{
MessageBox(NULL,"调试","错误",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
hwnd = CreateWindow("lidecheng","wocaonima",WS_OVERLAPPEDWINDOW,100,100,right,bottom,NULL,NULL,hInstance,NULL);
if(!hwnd)
{
return FALSE;
}
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
reshape(bottom,width);
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
MSG nMsg;
BOOL done = FALSE;
if(!CreateWindowGL(500,500))
{
return 0;
}
while(!done)
{
if(PeekMessage(&nMsg,NULL,0,0,PM_REMOVE))
{
if(nMsg.message = WM_QUIT)
{
done = TRUE;
}
else
{
TranslateMessage(&nMsg);
DispatchMessage(&nMsg);
}
}
else
{
display();
}
}
return (nMsg.wParam);
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
return 0;
/* case 'WM_KEYDOWN':
return 0;
case 'WM_KEYUP':
return 0;
case 'SIZE':
LOWORD(lParam),HIWORD(lParam);
LOWORD(lParam),HIWORD(lParam);
return 0;*/
default :
return 0;
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
为什么我显示不出来窗口,并且和这个物体!
请哥哥姐姐帮帮我解决这个问题下下!
thank you !