01 学习目标
(1) How to create and compile shader code
(2) How to draw with OpenGL
(3) How to use the book's application framework to initialize your programs and clean up after yourself.
02. 程序框架
To create an application, we simply include sb7, derive a class from sb7::application, and, in exactly one of our source files, include an instance of the DECLARE_MAIN macro.This defines the main entry point of out application, which create an instance of our class (the type of which is passed as a parameter to the macro) and calls its run() method, which implements the application's main loop.
virtual void run(sb7::application* the_app)
{
bool running = true;
app = the_app;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
return;
}
init();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, info.majorVersion);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, info.minorVersion);
#ifndef _DEBUG
if (info.flags.debug)
#endif /* _DEBUG */
{
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
}
if (info.flags.robust)
{
glfwWindowHint(GLFW_CONTEXT_ROBUSTNESS, GLFW_LOSE_CONTEXT_ON_RESET);
}
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_SAMPLES, info.samples);
glfwWindowHint(GLFW_STEREO, info.flags.stereo ? GL_TRUE : GL_FALSE);
// if (info.flags.fullscreen)
// {
// if (info.windowWidth == 0 || info.windowHeight == 0)
// {
// GLFWvidmode mode;
// glfwGetDesktopMode(&mode);
// info.windowWidth = mode.Width;
// info.windowHeight = mode.Height;
// }
//
// glfwOpenWindow(info.windowWidth, info.windowHeight, 8, 8, 8, 0, 32, 0, GLFW_FULLSCREEN);
// glfwSwapInterval((int)info.flags.vsync);
// }
// else
{
window = glfwCreateWindow(info.windowWidth, info.windowHeight, info.title, info.flags.fullscreen ? glfwGetPrimaryMonitor() : NULL, NULL);
if (!windo