2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
|
2013-02-16 20:03:21 +00:00
|
|
|
#if defined(__APPLE__)
|
2013-06-26 07:52:57 +00:00
|
|
|
#if defined(OSD_USES_GLEW)
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#else
|
|
|
|
#include <OpenGL/gl3.h>
|
|
|
|
#endif
|
2013-02-16 20:03:21 +00:00
|
|
|
#define GLFW_INCLUDE_GL3
|
|
|
|
#define GLFW_NO_GLU
|
|
|
|
#else
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#if defined(WIN32)
|
|
|
|
#include <GL/wglew.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-06-26 07:52:57 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-02-16 20:03:21 +00:00
|
|
|
#if defined(GLFW_VERSION_3)
|
2013-06-20 18:53:33 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
2013-02-16 20:03:21 +00:00
|
|
|
GLFWwindow* g_window=0;
|
|
|
|
GLFWmonitor* g_primary=0;
|
|
|
|
#else
|
|
|
|
#include <GL/glfw.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern void initOsd();
|
|
|
|
extern void updateGeom();
|
|
|
|
extern void display();
|
|
|
|
extern int g_width, g_height, g_frame;
|
|
|
|
|
|
|
|
static bool g_running = true;
|
|
|
|
|
|
|
|
static void
|
|
|
|
setGLCoreProfile()
|
|
|
|
{
|
|
|
|
#if GLFW_VERSION_MAJOR>=3
|
|
|
|
#define glfwOpenWindowHint glfwWindowHint
|
|
|
|
#define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR
|
|
|
|
#define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
#if not defined(__APPLE__)
|
2013-03-18 23:55:41 +00:00
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
|
2013-02-16 20:03:21 +00:00
|
|
|
#else
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
|
|
|
|
#endif
|
2013-09-12 17:14:48 +00:00
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
2013-02-16 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ### Misc. GLFW Callback Methods
|
|
|
|
|
|
|
|
// Reshape is called when the window is resized, here we need the width and
|
|
|
|
// height so that we can correctly adjust the aspect ratio of the projection
|
|
|
|
// matrix.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
#if GLFW_VERSION_MAJOR>=3
|
|
|
|
reshape(GLFWwindow *, int width, int height) {
|
|
|
|
#else
|
|
|
|
reshape(int width, int height) {
|
|
|
|
#endif
|
|
|
|
g_width = width;
|
|
|
|
g_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if GLFW_VERSION_MAJOR>=3
|
2013-03-17 01:44:53 +00:00
|
|
|
void windowClose(GLFWwindow*) {
|
|
|
|
g_running = false;
|
|
|
|
}
|
2013-02-16 20:03:21 +00:00
|
|
|
#else
|
|
|
|
int windowClose() {
|
|
|
|
g_running = false;
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
2013-03-17 01:44:53 +00:00
|
|
|
#endif
|
2013-02-16 20:03:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Idle is called between frames, here we advance the frame number and update
|
|
|
|
// the procedural animation that is being applied to the mesh
|
|
|
|
//
|
|
|
|
void
|
|
|
|
idle()
|
|
|
|
{
|
|
|
|
g_frame++;
|
|
|
|
updateGeom();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Setup GLFW, glew and some initial GL state
|
|
|
|
//
|
|
|
|
static const char windowTitle[] = "CPU Subdivision Example";
|
|
|
|
|
|
|
|
if (not glfwInit()) {
|
|
|
|
printf("Failed to initialize GLFW\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2013-02-16 21:10:00 +00:00
|
|
|
|
|
|
|
#define CORE_PROFILE
|
|
|
|
#ifdef CORE_PROFILE
|
2013-02-16 20:03:21 +00:00
|
|
|
setGLCoreProfile();
|
2013-02-16 21:10:00 +00:00
|
|
|
#endif
|
2013-02-16 20:03:21 +00:00
|
|
|
|
|
|
|
#if GLFW_VERSION_MAJOR>=3
|
|
|
|
if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, NULL, NULL))) {
|
|
|
|
printf("Failed to open window.\n");
|
|
|
|
glfwTerminate();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
glfwMakeContextCurrent(g_window);
|
2014-02-22 03:25:00 +00:00
|
|
|
|
|
|
|
// accommodate high DPI displays (e.g. mac retina displays)
|
|
|
|
glfwGetFramebufferSize(g_window, &g_width, &g_height);
|
|
|
|
glfwSetFramebufferSizeCallback(g_window, reshape);
|
|
|
|
|
2013-02-19 18:14:56 +00:00
|
|
|
glfwSetWindowCloseCallback(g_window, windowClose);
|
2013-02-16 20:03:21 +00:00
|
|
|
#else
|
|
|
|
if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8, GLFW_WINDOW) == GL_FALSE) {
|
|
|
|
printf("Failed to open window.\n");
|
|
|
|
glfwTerminate();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
glfwSetWindowTitle(windowTitle);
|
|
|
|
glfwSetWindowSizeCallback(reshape);
|
2013-02-19 18:14:56 +00:00
|
|
|
glfwSetWindowCloseCallback(windowClose);
|
2013-02-16 20:03:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-26 07:52:57 +00:00
|
|
|
#if defined(OSD_USES_GLEW)
|
2013-02-16 20:03:21 +00:00
|
|
|
#ifdef CORE_PROFILE
|
|
|
|
// this is the only way to initialize glew correctly under core profile context.
|
|
|
|
glewExperimental = true;
|
|
|
|
#endif
|
|
|
|
if (GLenum r = glewInit() != GLEW_OK) {
|
|
|
|
printf("Failed to initialize glew. Error = %s\n", glewGetErrorString(r));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#ifdef CORE_PROFILE
|
|
|
|
// clear GL errors which was generated during glewInit()
|
|
|
|
glGetError();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
initOsd();
|
|
|
|
|
|
|
|
//
|
2013-02-16 21:15:29 +00:00
|
|
|
// Start the main drawing loop
|
2013-02-16 20:03:21 +00:00
|
|
|
//
|
|
|
|
while (g_running) {
|
|
|
|
idle();
|
|
|
|
display();
|
|
|
|
|
|
|
|
#if GLFW_VERSION_MAJOR>=3
|
|
|
|
glfwPollEvents();
|
|
|
|
glfwSwapBuffers(g_window);
|
|
|
|
#else
|
|
|
|
glfwSwapBuffers();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
glFinish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|