本文整理汇总了C++中TestWindow::drawAll方法的典型用法代码示例。如果您正苦于以下问题:C++ TestWindow::drawAll方法的具体用法?C++ TestWindow::drawAll怎么用?C++ TestWindow::drawAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestWindow
的用法示例。
在下文中一共展示了TestWindow::drawAll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int /* argc */, char ** /* argv */)
{
SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
SDL_Window *window; // Declare a pointer to an SDL_Window
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,3);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
int winWidth = 1024;
int winHeight = 768;
// Create an application window with the following settings:
window = SDL_CreateWindow(
"An SDL2 window", // const char* title
SDL_WINDOWPOS_UNDEFINED, // int x: initial x position
SDL_WINDOWPOS_UNDEFINED, // int y: initial y position
winWidth, // int w: width, in pixels
winHeight, // int h: height, in pixels
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN // Uint32 flags: window options, see docs
);
// Check that the window was successfully made
if(window==NULL){
// In the event that the window could not be made...
std::cout << "Could not create window: " << SDL_GetError() << '\n';
SDL_Quit();
return 1;
}
auto context = SDL_GL_CreateContext(window);
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED );
TestWindow *screen = new TestWindow( window, winWidth, winHeight );
bool quit = false;
try
{
//nanogui::init();
//Event handler
SDL_Event e;
//nanogui::ref<ExampleApplication> app = new ExampleApplication();
while( !quit )
{
//Handle events on queue
while( SDL_PollEvent( &e ) != 0 )
{
//User requests quit
if( e.type == SDL_QUIT )
{
quit = true;
}
screen->onEvent( e );
}
SDL_SetRenderDrawColor(renderer, 0xd3, 0xd3, 0xd3, 0xff );
SDL_RenderClear( renderer );
screen->drawAll();
SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff );
SDL_Rect r{ 0, 0, 20, 30 };
SDL_RenderFillRect( renderer, &r );
//Update screen
SDL_GL_SwapWindow(window);
}
//nanogui::shutdown();
}
catch (const std::runtime_error &e)
{
std::string error_msg = std::string("Caught a fatal error: ") + std::string(e.what());
#if defined(_WIN32)
MessageBoxA(nullptr, error_msg.c_str(), NULL, MB_ICONERROR | MB_OK);
#else
std::cerr << error_msg << endl;
#endif
return -1;
}
return 0;
}