Max 5 API Reference
00001 // jit.gl.simple.c 00002 // sample GL group object which draws a simple quadrilateral. no matrixoutput. 00003 // Copyright 2002-2005 - Cycling '74 00004 00005 00006 #include "jit.common.h" 00007 #include "jit.gl.h" 00008 00009 typedef struct _jit_gl_simple 00010 { 00011 // Max object 00012 t_object ob; 00013 // 3d object extension. This is what all objects in the GL group have in common. 00014 void *ob3d; 00015 } t_jit_gl_simple; 00016 00017 void *_jit_gl_simple_class; 00018 00019 t_jit_err jit_gl_simple_init(void); 00020 t_jit_gl_simple *jit_gl_simple_new(t_symbol * dest_name); 00021 void jit_gl_simple_free(t_jit_gl_simple *x); 00022 00023 t_jit_err jit_gl_simple_draw(t_jit_gl_simple *x); 00024 t_jit_err jit_gl_simple_dest_closing(t_jit_gl_simple *x); 00025 t_jit_err jit_gl_simple_dest_changed(t_jit_gl_simple *x); 00026 t_jit_err build_simple_chunk(t_jit_gl_simple *x); 00027 00028 00029 // -------------------------------------------------------------------------------- 00030 00031 t_jit_err jit_gl_simple_init(void) 00032 { 00033 long ob3d_flags = JIT_OB3D_NO_MATRIXOUTPUT; // no matrix output 00034 void *ob3d; 00035 00036 _jit_gl_simple_class = jit_class_new("jit_gl_simple", 00037 (method)jit_gl_simple_new, (method)jit_gl_simple_free, 00038 sizeof(t_jit_gl_simple),A_DEFSYM,0L); 00039 00040 // set up object extension for 3d object, customized with flags 00041 ob3d = jit_ob3d_setup(_jit_gl_simple_class, 00042 calcoffset(t_jit_gl_simple, ob3d), 00043 ob3d_flags); 00044 00045 // define our OB3D draw method. called in automatic mode by 00046 // jit.gl.render or otherwise through ob3d when banged. this 00047 // method is A_CANT because our draw setup needs to happen 00048 // in the ob3d beforehand to initialize OpenGL state 00049 jit_class_addmethod(_jit_gl_simple_class, 00050 (method)jit_gl_simple_draw, "ob3d_draw", A_CANT, 0L); 00051 00052 // define our dest_closing and dest_changed methods. 00053 // these methods are called by jit.gl.render when the 00054 // destination context closes or changes: for example, when 00055 // the user moves the window from one monitor to another. Any 00056 // resources your object keeps in the OpenGL machine 00057 // (e.g. textures, display lists, vertex shaders, etc.) 00058 // will need to be freed when closing, and rebuilt when it has 00059 // changed. In this object, these functions do nothing, and 00060 // could be omitted. 00061 jit_class_addmethod(_jit_gl_simple_class, 00062 (method)jit_gl_simple_dest_closing, "dest_closing", A_CANT, 0L); 00063 jit_class_addmethod(_jit_gl_simple_class, 00064 (method)jit_gl_simple_dest_changed, "dest_changed", A_CANT, 0L); 00065 00066 // must register for ob3d use 00067 jit_class_addmethod(_jit_gl_simple_class, 00068 (method)jit_object_register, "register", A_CANT, 0L); 00069 00070 jit_class_register(_jit_gl_simple_class); 00071 00072 return JIT_ERR_NONE; 00073 } 00074 00075 00076 t_jit_gl_simple *jit_gl_simple_new(t_symbol * dest_name) 00077 { 00078 t_jit_gl_simple *x; 00079 00080 // make jit object 00081 if (x = (t_jit_gl_simple *)jit_object_alloc(_jit_gl_simple_class)) 00082 { 00083 // create and attach ob3d 00084 jit_ob3d_new(x, dest_name); 00085 } 00086 else 00087 { 00088 x = NULL; 00089 } 00090 return x; 00091 } 00092 00093 00094 void jit_gl_simple_free(t_jit_gl_simple *x) 00095 { 00096 // free our ob3d data 00097 jit_ob3d_free(x); 00098 } 00099 00100 00101 t_jit_err jit_gl_simple_draw(t_jit_gl_simple *x) 00102 { 00103 t_jit_err result = JIT_ERR_NONE; 00104 00105 // draw our OpenGL geometry. 00106 glBegin(GL_QUADS); 00107 glVertex3f(-1,-1,0); 00108 glVertex3f(-1,1,0); 00109 glVertex3f(1,1,0); 00110 glVertex3f(1,-1,0); 00111 glEnd(); 00112 00113 return result; 00114 } 00115 00116 t_jit_err jit_gl_simple_dest_closing(t_jit_gl_simple *x) 00117 { 00118 // nothing in this object to free. 00119 return JIT_ERR_NONE; 00120 } 00121 00122 t_jit_err jit_gl_simple_dest_changed(t_jit_gl_simple *x) 00123 { 00124 // nothing in this object to update. 00125 return JIT_ERR_NONE; 00126 } 00127 00128
Copyright © 2008, Cycling '74