增加新的OutputGLInfo范例
This commit is contained in:
parent
f3065b26af
commit
8abbf0117d
@ -1,2 +1,4 @@
|
|||||||
add_subdirectory(EnumRenderDevice)
|
add_subdirectory(EnumRenderDevice)
|
||||||
|
add_subdirectory(OutputGLInfo)
|
||||||
add_subdirectory(NullWindow)
|
add_subdirectory(NullWindow)
|
||||||
|
add_subdirectory(DrawTriangle)
|
||||||
|
4
example/DrawTriangle/CMakeLists.txt
Normal file
4
example/DrawTriangle/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
add_executable(DrawTriangle main.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(DrawTriangle PRIVATE glfw GL ULRE.RenderDevice)
|
||||||
|
|
54
example/DrawTriangle/main.cpp
Normal file
54
example/DrawTriangle/main.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#include<hgl/render/RenderDevice.h>
|
||||||
|
#include<hgl/render/RenderWindow.h>
|
||||||
|
#include<iostream>
|
||||||
|
#include<GLFW/glfw3.h>
|
||||||
|
#include<GL/glext.h>
|
||||||
|
|
||||||
|
using namespace hgl;
|
||||||
|
|
||||||
|
void draw()
|
||||||
|
{
|
||||||
|
glClearColor(0,0,0,1); //设置清屏颜色
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT); //清屏
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
RenderDevice *device=CreateRenderDeviceGLFW();
|
||||||
|
|
||||||
|
if(!device)
|
||||||
|
{
|
||||||
|
std::cerr<<"Create RenderDevice(GLFW) failed."<<std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!device->Init())
|
||||||
|
{
|
||||||
|
std::cerr<<"Init RenderDevice(GLFW) failed."<<std::endl;
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowSetup ws;
|
||||||
|
|
||||||
|
ws.Name=U8_TEXT("Draw Triangle");
|
||||||
|
|
||||||
|
RenderSetup rs;
|
||||||
|
|
||||||
|
RenderWindow *win=device->CreateWindow(1280,720,&ws,&rs);
|
||||||
|
|
||||||
|
win->MakeToCurrent(); //切换当前窗口到前台
|
||||||
|
win->Show();
|
||||||
|
|
||||||
|
while(win->IsOpen())
|
||||||
|
{
|
||||||
|
draw();
|
||||||
|
|
||||||
|
win->SwapBuffer(); //交换前后台显示缓冲区
|
||||||
|
win->PollEvent(); //处理窗口事件
|
||||||
|
}
|
||||||
|
|
||||||
|
delete win;
|
||||||
|
delete device;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
5
example/OutputGLInfo/CMakeLists.txt
Normal file
5
example/OutputGLInfo/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
add_executable(OutputGLInfo main.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(OutputGLInfo PRIVATE glfw GL ULRE.RenderDevice)
|
||||||
|
|
||||||
|
|
70
example/OutputGLInfo/main.cpp
Normal file
70
example/OutputGLInfo/main.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include<hgl/render/RenderDevice.h>
|
||||||
|
#include<hgl/render/RenderWindow.h>
|
||||||
|
#include<iostream>
|
||||||
|
#include<GLFW/glfw3.h>
|
||||||
|
#include<GL/glext.h>
|
||||||
|
|
||||||
|
using namespace hgl;
|
||||||
|
|
||||||
|
void draw()
|
||||||
|
{
|
||||||
|
glClearColor(0,0,0,1); //设置清屏颜色
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT); //清屏
|
||||||
|
}
|
||||||
|
|
||||||
|
void output_ogl_info()
|
||||||
|
{
|
||||||
|
std::cout<<"Vendor: "<<glGetString(GL_VENDOR)<<std::endl;
|
||||||
|
std::cout<<"Renderer: "<<glGetString(GL_RENDERER)<<std::endl;
|
||||||
|
std::cout<<"Version: "<<glGetString(GL_VERSION)<<std::endl;
|
||||||
|
|
||||||
|
PFNGLGETSTRINGIPROC glGetStringi = (PFNGLGETSTRINGIPROC)glfwGetProcAddress("glGetStringi");
|
||||||
|
|
||||||
|
if(!glGetStringi)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GLint n=0;
|
||||||
|
|
||||||
|
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
|
||||||
|
|
||||||
|
std::cout<<"Extensions:"<<std::endl;
|
||||||
|
|
||||||
|
for (GLint i=0; i<n; i++)
|
||||||
|
std::cout<<" "<<i<<" : "<<glGetStringi(GL_EXTENSIONS,i)<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
RenderDevice *device=CreateRenderDeviceGLFW();
|
||||||
|
|
||||||
|
if(!device)
|
||||||
|
{
|
||||||
|
std::cerr<<"Create RenderDevice(GLFW) failed."<<std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!device->Init())
|
||||||
|
{
|
||||||
|
std::cerr<<"Init RenderDevice(GLFW) failed."<<std::endl;
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowSetup ws;
|
||||||
|
|
||||||
|
ws.Name=U8_TEXT("Draw Triangle");
|
||||||
|
|
||||||
|
RenderSetup rs;
|
||||||
|
|
||||||
|
RenderWindow *win=device->CreateWindow(1280,720,&ws,&rs);
|
||||||
|
|
||||||
|
win->MakeToCurrent(); //切换当前窗口到前台
|
||||||
|
|
||||||
|
output_ogl_info();
|
||||||
|
|
||||||
|
delete win;
|
||||||
|
delete device;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user