📄 minigl.c
字号:
}static PyObject *pygluCylinder(PyObject *s, PyObject *o) { Quadric *q; double base, top, height; int slices, stacks; if(!PyArg_ParseTuple(o, "O!dddii:gluCylinder", &Quadric_Type, &q, &base, &top, &height, &slices, &stacks)) return NULL; if(!q->q) { PyErr_SetString(PyExc_TypeError, "Operation on deleted quadric"); return NULL; } gluCylinder(q->q, base, top, height, slices, stacks); CHECK_ERROR; Py_INCREF(Py_None); return Py_None;}static PyObject *pygluDisk(PyObject *s, PyObject *o) { Quadric *q; double inner, outer; int slices, loops; if(!PyArg_ParseTuple(o, "O!ddii:gluDisk", &Quadric_Type, &q, &inner, &outer, &slices, &loops)) return NULL; if(!q->q) { PyErr_SetString(PyExc_TypeError, "Operation on deleted quadric"); return NULL; } gluDisk(q->q, inner, outer, slices, loops); CHECK_ERROR; Py_INCREF(Py_None); return Py_None;}static PyObject *pygluQuadricOrientation(PyObject *s, PyObject *o) { Quadric *q; int orient; if(!PyArg_ParseTuple(o, "O!i:gluQuadricOrientation", &Quadric_Type, &q, &orient)) return NULL; if(!q->q) { PyErr_SetString(PyExc_TypeError, "Operation on deleted quadric"); return NULL; } gluQuadricOrientation(q->q, orient); CHECK_ERROR; Py_INCREF(Py_None); return Py_None;}static PyObject *pygluLookAt(PyObject *s, PyObject *o) { double eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz; if(!PyArg_ParseTuple(o, "ddddddddd:gluLookAt", &eyex, &eyey, &eyez, ¢erx, ¢ery, ¢erz, &upx, &upy, &upz)) return NULL; gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz); CHECK_ERROR; Py_INCREF(Py_None); return Py_None;}static PyObject *pygluPickMatrix(PyObject *s, PyObject *o) { double x, y, delx, dely; int viewport[4]; if(!PyArg_ParseTuple(o, "dddd(iiii):gluPickMatrix", &x, &y, &delx, &dely, viewport, viewport+1, viewport+2, viewport+3)) return NULL; gluPickMatrix(x, y, delx, dely, viewport); CHECK_ERROR; Py_INCREF(Py_None); return Py_None;}static PyObject *pygluProject(PyObject *s, PyObject *o) { double x, y, z, wx, wy, wz, model[16], proj[16]; int viewport[4]; if(!PyArg_ParseTuple(o, "ddd:gluProject", &x, &y, &z)) return NULL; glGetIntegerv(GL_VIEWPORT, viewport); glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetDoublev(GL_PROJECTION_MATRIX, proj); gluProject(x, y, z, model, proj, viewport, &wx, &wy, &wz); CHECK_ERROR; return Py_BuildValue("ddd", wx, wy, wz);}static PyObject *pygluUnProject(PyObject *s, PyObject *o) { double x, y, z, wx, wy, wz, model[16], proj[16]; int viewport[4]; if(!PyArg_ParseTuple(o, "ddd:gluUnProject", &x, &y, &z)) return NULL; glGetIntegerv(GL_VIEWPORT, viewport); glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetDoublev(GL_PROJECTION_MATRIX, proj); gluUnProject(x, y, z, model, proj, viewport, &wx, &wy, &wz); CHECK_ERROR; return Py_BuildValue("ddd", wx, wy, wz);}static GLuint *select_buffer = NULL;static PyObject *pyglSelectBuffer( PyObject *s, PyObject *o) { int sz; if(!PyArg_ParseTuple(o, "i:glSelectBuffer", &sz)) return NULL; if(select_buffer) select_buffer = realloc( select_buffer, sizeof(int) * sz); else select_buffer = malloc(sizeof(int) * sz); glSelectBuffer(sz, select_buffer); CHECK_ERROR; Py_INCREF(Py_None); return Py_None;}static GLfloat *feedback_buffer = NULL;static PyObject *pyglFeedbackBuffer( PyObject *s, PyObject *o) { int sz, ty; if(!PyArg_ParseTuple(o, "ii:glFeedbackBuffer", &sz, &ty)) return NULL; if(feedback_buffer) feedback_buffer = realloc( feedback_buffer, sizeof(int) * sz); else feedback_buffer = malloc(sizeof(int) * sz); glFeedbackBuffer(sz, ty, feedback_buffer); CHECK_ERROR; Py_INCREF(Py_None); return Py_None;}static PyObject *pyglRenderMode( PyObject *s, PyObject *o) { int mode, lastmode, count; if(!PyArg_ParseTuple(o, "i:glRenderMode", &mode)) return NULL; glGetIntegerv(GL_RENDER_MODE, &lastmode); count = glRenderMode(mode); CHECK_ERROR; if(lastmode == GL_SELECT) { PyObject *r = PyList_New(0); int i = 0; while(i < count) { PyObject *record = PyTuple_New(3); int namelen = select_buffer[i++]; PyObject *name = PyList_New(namelen); int j; PyTuple_SetItem(record, 0, PyFloat_FromDouble(select_buffer[i++] / 214748364.)); PyTuple_SetItem(record, 1, PyFloat_FromDouble(select_buffer[i++] / 214748364.)); for(j=0; namelen; namelen--, j++, i++) PyList_SetItem(name, j, PyInt_FromLong(select_buffer[i])); PyTuple_SetItem(record, 2, name); PyList_Append(r, record); Py_DECREF(record); } return r; } else if(lastmode == GL_FEEDBACK ) { PyObject *r = PyList_New(count); int i; for(i=0; i < count; i++) { PyList_SET_ITEM(r, i, PyFloat_FromDouble(feedback_buffer[i])); } return r; } Py_INCREF(Py_None); return Py_None;}static PyObject *pydraw_lines(PyObject *s, PyObject *o) { PyListObject *li; int for_selection = 0; int i; int first = 1; int nl = -1, n; double lx=0, ly=0, lz=0; double p1[3], p2[3]; if(!PyArg_ParseTuple(o, "O!|i:draw_lines", &PyList_Type, &li, &for_selection)) return NULL; for(i=0; i<PyList_GET_SIZE(li); i++) { PyObject *it = PyList_GET_ITEM(li, i); PyObject *dummy1, *dummy2, *dummy3; if(!PyArg_ParseTuple(it, "i(ddd)(ddd)|OOO", &n, p1, p1+1, p1+2, p2, p2+1, p2+2, &dummy1, &dummy2, &dummy3)) { if(!first) glEnd(); return NULL; } if(first || p1[0] != lx || p1[1] != ly || p1[2] != lz || (for_selection && n != nl)) { if(!first) glEnd(); if(for_selection && n != nl) { glLoadName(n); nl = n; } glBegin(GL_LINE_STRIP); glVertex3dv(p1); first = 0; } glVertex3dv(p2); lx = p2[0]; ly = p2[1], lz = p2[2]; } if(!first) glEnd(); Py_INCREF(Py_None); return Py_None;}/*glSelectBuffer*/static PyMethodDef methods[] = {#define METH(name, doc) { #name, (PyCFunction) py##name, METH_VARARGS, doc }METH(glBegin, "delimit the vertices of a primitive or a group of like primitives"),METH(glColor3f, "set the current color"),METH(glColor4f, "set the current color"),METH(glBlendColor, "set the blend color"),METH(glDeleteLists, "delete a contiguous group of display lists"),METH(glBlendFunc, "specify pixel arithmetic"),METH(glCallList, "execute a display list"),METH(glClear, "clear buffers to preset values"),METH(glClearColor, "specify clear values for the color buffers"),METH(glColorMask, "specify which components of color to write"),METH(glDepthFunc, "specify the value used for depth buffer comparisons"),METH(glDepthMask, "enable or disable writing into the depth buffer"),METH(glDisable, "enable or disable server-side GL capabilities"),METH(glEnable, "enable or disable server-side GL capabilities"),METH(glEnd, "delimit the vertices of a primitive or a group of like primitives"),METH(glEndList, "create or replace a display list"),METH(glFlush, "force execution of GL commands in finite time"),METH(glFrontFace, "define front- and back-facing polygons"),METH(glInitNames, "initialize the name stack"),METH(glLightf, "set light source parameters"),METH(glLineStipple, "specify the line stipple pattern"),METH(glLineWidth, "specify the width of rasterized lines"),METH(glLoadIdentity, "replace the current matrix with the identity matrix"),METH(glLoadName, "load a name onto the name stack"),METH(glMatrixMode, "specify which matrix is the current matrix"),METH(glNewList, "create or replace a display list"),METH(glNormal3f, "set the current normal vector"),METH(glPolygonOffset, "set the scale and units used to calculate depth values"),METH(glPolygonStipple, "set the polygon stippling pattern"),METH(glPopMatrix, "push and pop the current matrix stack"),METH(glPushMatrix, "push and pop the current matrix stack"),METH(glPushName, "push and pop the name stack"),METH(glRenderMode, "set rasterization mode"),METH(glRasterPos2i, "specify the raster position for pixel operations"),METH(glRectf, "draw a rectangle"),METH(glRotatef, "multiply the current matrix by a rotation matrix"),METH(glScalef, "multiply the current matrix by a general scaling matrix"),METH(glStencilFunc, "specify the stencil buffer test function"),METH(glStencilOp, "specify the stencil buffer operation"),METH(glFlush, "force execution of GL commands in finite time"),METH(glDrawBuffer, "specify which color buffers are to be drawn into"),METH(glDrawArrays, "render primitives from array data"),METH(glMatrixMode, "specify which matrix is the current matrix"),METH(glOrtho, "multiply the current matrix with an orthographic matrix"),METH(glTranslatef, "multiply the current matrix by a translation matrix"),METH(glVertex3f, "specify a vertex"),METH(glViewport, "set the viewport"),METH(gluPerspective, "set up a perspective projection matrix"),METH(glGenLists, "generate a contiguous set of empty display lists"),METH(glGetDoublev, "return the value or values of a selected parameter"),METH(glGetIntegerv, "return the value or values of a selected parameter"),METH(glInterleavedArrays, "simultaneously specify and enable several interleaved arrays"),METH(glLightfv, "set light source parameters"),METH(glLightModelfv, "set the lighting model parameters"),METH(glLightModeli, "set the lighting model parameters"),METH(glMaterialfv, "specify material parameters for the lighting model"),METH(glMultMatrixd, "multiply the current matrix with the specified matrix"),METH(glPixelStorei, "set pixel storage modes"),METH(glSelectBuffer, "establish a buffer for selection mode values"),METH(glFeedbackBuffer, "establish a buffer for feedback mode values"),// METH(glVertex3fv, ""),METH(gluSphere, "draw a sphere"),METH(gluCylinder, "draw a cylinder"),METH(gluDeleteQuadric, "destroy a quadrics object"),METH(gluDisk, "draw a disk"),METH(gluLookAt, "define a viewing transformation"),METH(gluNewQuadric, "create a quadrics object"),METH(gluPickMatrix, "define a picking region"),METH(gluProject, "map object coordinates to window coordinates"),METH(gluQuadricOrientation, "specify inside/outside orientation for quadrics"),METH(gluUnProject, "map window coordinates to object coordinates"),METH(glBitmap, "draw a bitmap"),METH(glReadPixels, "read pixels"),METH(draw_lines, "Draw a bunch of lines in the 'rs274.glcanon' format"),#undef METH{NULL, NULL, 0, 0},};#define CONST(x) PyObject_SetAttrString(m, #x, PyInt_FromLong(x))void initminigl(void) { PyObject *m = \ Py_InitModule3("minigl", methods, "Mini version of pyopengl for axis"); glerror = PyErr_NewException("minigl.error", PyExc_RuntimeError, NULL); PyObject_SetAttrString(m, "error", glerror); CONST(GL_ALWAYS); CONST(GL_LEQUAL); CONST(GL_BACK); CONST(GL_BLEND); CONST(GL_COLOR_BUFFER_BIT); CONST(GL_COMPILE); CONST(GL_CULL_FACE); CONST(GL_DEPTH_BUFFER_BIT); CONST(GL_DEPTH_TEST); CONST(GL_FALSE); CONST(GL_FRONT); CONST(GL_FRONT_AND_BACK); CONST(GL_KEEP); CONST(GL_LESS); CONST(GL_LIGHTING); CONST(GL_LIGHTING); CONST(GL_LIGHT_MODEL_AMBIENT); CONST(GL_LIGHT_MODEL_LOCAL_VIEWER); CONST(GL_LINES); CONST(GL_LINE_LOOP); CONST(GL_LINE_STIPPLE); CONST(GL_LINE_STRIP); CONST(GL_MODELVIEW); CONST(GL_MODELVIEW_MATRIX); CONST(GL_ONE_MINUS_SRC_ALPHA); CONST(GL_CONSTANT_ALPHA); CONST(GL_ONE_MINUS_CONSTANT_ALPHA); CONST(GL_ONE); CONST(GL_PROJECTION); CONST(GL_PROJECTION_MATRIX); CONST(GL_QUADS); CONST(GL_RENDER); CONST(GL_REPLACE); CONST(GL_SELECT); CONST(GL_FEEDBACK); CONST(GL_SRC_ALPHA); CONST(GL_STACK_OVERFLOW); CONST(GL_STENCIL_BUFFER_BIT); CONST(GL_STENCIL_TEST); CONST(GL_TRUE); CONST(GL_UNPACK_ALIGNMENT); CONST(GL_V3F); CONST(GL_C3F_V3F); CONST(GL_C4UB_V3F); CONST(GL_VIEWPORT); CONST(GL_LIGHT0); CONST(GL_POSITION); CONST(GL_AMBIENT); CONST(GL_AMBIENT_AND_DIFFUSE); CONST(GL_DIFFUSE); CONST(GL_CCW); CONST(GL_DITHER); CONST(GL_AUTO_NORMAL); CONST(GL_NORMALIZE); CONST(GL_POLYGON_OFFSET_FILL); CONST(GL_POLYGON_STIPPLE); CONST(GL_POLYGON); CONST(GL_GREATER); CONST(GL_LIST_INDEX); CONST(GL_TRIANGLES); CONST(GL_TRIANGLE_FAN); CONST(GLU_INSIDE); CONST(GLU_OUTSIDE); CONST(GL_TEXTURE_2D); CONST(GL_2D); CONST(GL_3D); CONST(GL_3D_COLOR); CONST(GL_3D_COLOR_TEXTURE); CONST(GL_4D_COLOR_TEXTURE); CONST(GL_COMPILE_AND_EXECUTE);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -