demo-common.h (1591B)
1 /* 2 * Copyright 2012 Google, Inc. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 * Google Author(s): Behdad Esfahbod, Maysum Panju 17 */ 18 19 #ifndef DEMO_COMMON_H 20 #define DEMO_COMMON_H 21 22 #include "glyphy/glyphy.h" 23 24 #include <stdlib.h> 25 #include <stdio.h> 26 27 #include <GL/glew.h> 28 29 #if defined(__APPLE__) 30 # include <OpenGL/gl.h> 31 # include <OpenGL/glu.h> 32 #else 33 //# include <GLES2/gl2.h> 34 #endif 35 36 37 #define ARRAY_LEN(Array) (sizeof (Array) / sizeof (*Array)) 38 39 #define MIN_FONT_SIZE 10 40 #define TOLERANCE (1./2048) 41 42 #define LOGI(...) ((void) fprintf (stdout, __VA_ARGS__)) 43 #define LOGW(...) ((void) fprintf (stderr, __VA_ARGS__)) 44 #define LOGE(...) ((void) fprintf (stderr, __VA_ARGS__), abort ()) 45 46 template <typename T> 47 T clamp (T v, T m, T M) 48 { 49 return v < m ? m : v > M ? M : v; 50 } 51 52 struct auto_trace_t 53 { 54 auto_trace_t (const char *func_) : func (func_) 55 { printf ("Enter: %s\n", func); } 56 57 ~auto_trace_t (void) 58 { printf ("Leave: %s\n", func); } 59 60 private: 61 const char * const func; 62 }; 63 64 #define TRACE() auto_trace_t trace(__func__) 65 66 #endif /* DEMO_COMMON_H */