扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
你既可以建立Win32项目使用API,也可以建立MFC工程
创新互联公司是一家集网站建设,织金企业网站建设,织金品牌网站建设,网站定制,织金网站建设报价,网络营销,网络优化,织金网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
(一般不用MFC框架直接用API)
我给你一个例子吧,建立Win32空项目,添加一个cpp文件,编译执行就行了
(这是一个经典的opengl框架了)代码如下:
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
#pragma comment(lib,"glaux.lib")
#include windows.h
#include gl/gl.h
#include gl/glu.h
#include gl/glaux.h
HDC hDC=NULL;
HGLRC hRC=NULL;
HWND hWnd=NULL;
HINSTANCE hInstance;
BOOL keys[256];
BOOL active=TRUE;
BOOL fullscreen=TRUE;
GLfloat rtri;
GLfloat rquad;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
GLvoid ResizeGLScene(GLsizei width,GLsizei height)
{
if(height==0)
height=1;
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int InitGL(GLvoid)
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f,0.0f,0.0f,0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
return TRUE;
}
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glRotatef(rtri,0.0f,1.0f,0.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(1.0f,-1.0f,1.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(1.0f,-1.0f,1.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(1.0f,-1.0f,-1.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(1.0f,-1.0f,-1.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glEnd();
glLoadIdentity();
glTranslatef(1.5f,0.0f,-7.0f);
glRotatef(rquad,1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,1.0f,1.0f);
glVertex3f(1.0f,1.0f,1.0f);
glColor3f(1.0f,0.5f,0.0f);
glVertex3f(1.0f,-1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(1.0f,-1.0f,-1.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,1.0f,1.0f);
glVertex3f(-1.0f,1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glVertex3f(1.0f,-1.0f,1.0f);
glColor3f(1.0f,1.0f,0.0f);
//glVertex3f(1.0f,-1.0f,-1.0f);
//glVertex3f(-1.0f,-1.0f,-1.0f);
//glVertex3f(-1.0f,1.0f,-1.0f);
//glVertex3f(1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(1.0f,1.0f,-1.0f);
glVertex3f(1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,1.0f,1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glColor3f(1.0f,0.0f,1.0f);
glVertex3f(1.0f,1.0f,-1.0f);
glVertex3f(1.0f,1.0f,1.0f);
glVertex3f(1.0f,-1.0f,1.0f);
glVertex3f(1.0f,-1.0f,-1.0f);
glEnd();
rtri+=0.2f;
rquad-=0.15f;
return TRUE;
}
GLvoid KillGLWindow(GLvoid)
{
if(fullscreen)
{
ChangeDisplaySettings(NULL,0);
ShowCursor(TRUE);
}
if(hRC)
{
if(!wglMakeCurrent(NULL,NULL))
MessageBox(NULL,"释放DC或RC失败","关闭错误",MB_OK|MB_ICONINFORMATION);
if(!wglDeleteContext(hRC))
MessageBox(NULL,"释放RC失败","关闭错误",MB_OK|MB_ICONINFORMATION);
hRC=NULL;
}
if(hDC !ReleaseDC(hWnd,hDC))
{
MessageBox(NULL,"释放DC失败","关闭错误",MB_OK|MB_ICONINFORMATION);
hDC=NULL;
}
if(hWnd !DestroyWindow(hWnd))
{
MessageBox(NULL,"释放窗口句柄失败","关闭错误",MB_OK|MB_ICONINFORMATION);
hWnd=NULL;
}
if(!UnregisterClass("OpenG",hInstance))
{
MessageBox(NULL,"不能注销窗口类","关闭错误",MB_OK|MB_ICONINFORMATION);
hInstance=NULL;
}
}
BOOL CreateGLWindow(char* title,int width,int height,int bits,BOOL fullscreenflag)
{
GLuint PixelFormat;
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left=(long)0;
WindowRect.right=(long)width;
WindowRect.top=(long)0;
WindowRect.bottom=(long)height;
fullscreen=fullscreenflag;
hInstance=GetModuleHandle(NULL);
wc.style=CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
wc.lpfnWndProc=(WNDPROC)WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=NULL;
wc.lpszMenuName=NULL;
wc.lpszClassName="OpenG";
if(!RegisterClass(wc))
{
MessageBox(NULL,"注册窗口失败","错误",MB_OK|MB_ICONINFORMATION);
return FALSE;
}
if(fullscreen)
{
DEVMODE dmScreenSettings;
memset(dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth=width;
dmScreenSettings.dmPelsHeight=height;
dmScreenSettings.dmBitsPerPel=bits;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
if(ChangeDisplaySettings(dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
if(MessageBox(NULL,"全屏模式设置失败!\n使用窗口模式?","OpenGL 3D游戏编程",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen=FALSE;
}
else
{
MessageBox(NULL,"程序将被关闭","错误",MB_OK|MB_ICONINFORMATION);
return FALSE;
}
}
}
if(fullscreen)
{
dwExStyle=WS_EX_APPWINDOW;
dwStyle=WS_POPUP;
ShowCursor(FALSE);
}
else
{
dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
dwStyle=WS_OVERLAPPEDWINDOW;
}
AdjustWindowRectEx(WindowRect,dwStyle,FALSE,dwExStyle);
if(!(hWnd=CreateWindowEx(dwExStyle,"OpenG",title,
dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,0,0,
WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,
NULL,NULL,hInstance,NULL)))
{
KillGLWindow();
MessageBox(NULL,"窗口创建失败","错误",MB_OK|MB_ICONINFORMATION);
return FALSE;
}
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),1,
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,bits,
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
if(!(hDC=GetDC(hWnd)))
{
KillGLWindow();
MessageBox(NULL,"不能创建一个窗口设备描述表","错误",MB_OK|MB_ICONINFORMATION);
return FALSE;
}
if(!(PixelFormat=ChoosePixelFormat(hDC,pfd)))
{
KillGLWindow();
MessageBox(NULL,"不能创建一个匹配的像素格式","错误",MB_OK|MB_ICONINFORMATION);
return FALSE;
}
if(!SetPixelFormat(hDC,PixelFormat,pfd))
{
KillGLWindow();
MessageBox(NULL,"不能设置像素格式","错误",MB_OK|MB_ICONINFORMATION);
return FALSE;
}
if(!(hRC=wglCreateContext(hDC)))
{
KillGLWindow();
MessageBox(NULL,"不能创建OpenGL渲染描述表","错误",MB_OK|MB_ICONINFORMATION);
return FALSE;
}
if(!wglMakeCurrent(hDC,hRC))
{
KillGLWindow();
MessageBox(NULL,"不能激活当前的OpenGL渲染描述表","错误",MB_OK|MB_ICONINFORMATION);
return FALSE;
}
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
ResizeGLScene(width,height);
if(!InitGL())
{
KillGLWindow();
MessageBox(NULL,"初始化失败","错误",MB_OK|MB_ICONINFORMATION);
return FALSE;
}
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_ACTIVATE:
{
if(!HIWORD(wParam))
active=TRUE;
else
active=FALSE;
return 0;
}
case WM_SYSCOMMAND:
{
switch(wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
}
case WM_KEYDOWN:
{
keys[wParam]=TRUE;
return 0;
}
case WM_KEYUP:
{
keys[wParam]=FALSE;
return 0;
}
case WM_SIZE:
{
ResizeGLScene(LOWORD(lParam),HIWORD(lParam));
return 0;
}
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
BOOL done=FALSE;
if(MessageBox(NULL,"你想在全屏模式下运行吗?","设置全屏模式",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=FALSE;
}
if(!CreateGLWindow("Win32 SDK风格 OpenGL程序框架",640,480,16,fullscreen))
return 0;
while(!done)
{
if(PeekMessage(msg,NULL,0,0,PM_REMOVE))
{
if(msg.message==WM_QUIT)
done=TRUE;
else
{
TranslateMessage(msg);
DispatchMessage(msg);
}
}
else
{
if(active)
{
if(keys[VK_ESCAPE])
done=TRUE;
else
{
DrawGLScene();
SwapBuffers(hDC);
}
}
if(keys[VK_F1])
{
keys[VK_F1]=FALSE;
KillGLWindow();
fullscreen=!fullscreen;
if(!CreateGLWindow("Win32 SDK风格 OpenGL程序框架",640,480,16,fullscreen))
return 0;
}
}
}
KillGLWindow();
return msg.wParam;
}
1.将开发库中的.h文件拷贝到Visual C++2008的\Include\GL目录中
2.将.lib文件拷贝到Visual C++2008的\lib目录中
3.将.dll文件拷贝到操作系统的system32目录中
先看一下里面有没有对应的 glaux.h glaux.lib 没有的话网上下一个,或者给我邮箱我发给你也行
Go 语言是一个试图结合动态类型和静态类型,编译效率和安全性以及语言的易用性等众多特性与一体的一种尝试。他的另一个目标是支持现代的基于网络的、基于多核的计算。最后,Go 还是非常快的,他可以在单个计算机上仅仅花费几秒时间构建一个庞大的应用程序。使用GO语言开发android语言步骤如下:
1. 下载安装Go语言(版本1.5+)
Golang链接
回到顶部
2. 下载安装 gomobile
下载
$ go get golang.org/x/mobile/cmd/gomobile
安装(需要等待几分钟)
gomobile init
回到顶部
3. Golang开发手机应用有两种方式
a. 原生应用开发
$ go get -d golang.org/x/mobile/example/basic
主要应用领域:
应用控制管理与配置
OpenGL ES 2 绑定
Asset 管理
Event 管理
试验中的包,含有OpenAL 绑定、音频、字体、图形以及运动传感器
Android开发
$ gomobile build -target=android golang.org/x/mobile/example/basic
此命令会生成名为basic的apk安装包
$ gomobile install golang.org/x/mobile/example/basic
此命令将安装apk包到已连接的android设备
Golang提供了一些GPU编程库,例如CUDA、OpenCL和OpenACC等等。这些库允许您使用Golang编写并发的GPU应用程序。下面是使用Golang调用GPU的步骤:
1. 确保您已经安装了CUDA、OpenCL或OpenACC。
2. 使用Golang编写相应的GPU程序,例如使用CUDA编写的程序可以使用GoCudnn库。这个库提供了一系列用于GPU深度学习的函数,并且可以在Golang中轻松调用CUDA加速的算法。另外,还有Gorgonia库,该库使用了CUDA,OpenCL和TensorFlow等库,使得Golang具有快速计算张量的能力。
3. 编写能够与GPU通信的代码,例如在CUDA中,你需要将Golang数据转换为相应的CUDA数据类型。
4. 将代码编译为可执行文件。
5. 运行程序并使用GPU执行计算操作。
请注意,GPU编程需要一定的专业知识。如果您没有GPU编程经验,可以参考一些在线学习资源来了解相关的技术。
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流