def _initTextureEnv(have_mipmaps): """ have_mipmaps is boolean #doc Anything that calls this should eventually call glpane.kluge_reset_texture_mode_to_work_around_renderText_bug(), but only after all drawing using the texture is done. """ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) # [looks like a bug that we overwrite clamp with repeat, just below? # bruce 060212 comment] glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) if (0 and "kluge" and debug_pref("smoother textures", Choice_boolean_False, prefs_key=True)): ###@@@ revise to param #bruce 060212 new feature (only visible in debug version so far); # ideally it'd be controllable per-jig for side-by-side comparison; # also, changing its menu item ought to gl_update but doesn't ##e glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) if have_mipmaps: ###@@@ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) return
def _initTextureEnv(self): # called during draw method glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) # [looks like a bug that we overwrite clamp with repeat, just # below? bruce 060212 comment] glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) if debug_pref("smoother textures", Choice_boolean_False, prefs_key=True): #bruce 060212 new feature (only visible in debug version so far); # ideally it'd be controllable per-jig for side-by-side comparison; # also, changing its menu item ought to gl_update but doesn't ##e glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) if self.have_mipmaps: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) return
def initTextureEnv(have_mipmaps): "have_mipmaps is boolean #doc" glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) # [looks like a bug that we overwrite clamp with repeat, just below? # bruce 060212 comment] glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) if (0 and "kluge" and debug_pref("smoother textures", Choice_boolean_False, prefs_key = True)): ###@@@ revise to param #bruce 060212 new feature (only visible in debug version so far); # ideally it'd be controllable per-jig for side-by-side comparison; # also, changing its menu item ought to gl_update but doesn't ##e glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) if have_mipmaps: #####@@@@@ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) return
def bind_texture(self, clamp=False, use_mipmaps=True, decal=False, pixmap=False): """ bind our texture, and set texture-related GL params as specified. Anything that calls this should eventually call self.kluge_reset_texture_mode_to_work_around_renderText_bug(), but only after all drawing using the texture is done. """ # Notes [some of this belongs in docstring]: #e - we might want to pass these tex params as one chunk, or a flags word #e - we might want to optim for when they don't change # - most of them have default values like the old code had implicitly, but not pixmap, which old code had as implicitly true # - pixmap is misnamed, it doesn't use the pixmap ops, tho we might like to use those from the same image data someday have_mipmaps, tex_name = self.loaded_texture_data ## texture_helpers.setup_to_draw_texture_name(have_mipmaps, tex_name) # let's inline that instead, including its call of _initTextureEnv, and then modify it [061126] glBindTexture(GL_TEXTURE_2D, tex_name) # modified from _initTextureEnv(have_mipmaps) in texture_helpers.py if clamp: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) if not pixmap: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) if have_mipmaps and use_mipmaps: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) if decal: glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) else: # see red book p410-411 -- can use GL_DECAL, GL_REPLACE, GL_MODULATE, GL_BLEND, GL_ADD, GL_COMBINE. # (Except that I can't import GL_COMBINE (iMac G5) so maybe it's not always available.) # GL_DECAL leaves fragment alpha unchanged and uses texture alpha to mix its color with fragment color # (fragment data comes from the polygon's alpha & color as if drawn untextured). # GL_REPLACE just discards fragment data in favor of texture data incl alpha -- that would be a better default. # [later 070404: now it is the default.] # Eventually permit all these values -- for now just let decal = False mean GL_REPLACE. [070403] # ## print "getTextureData", self, self._image.getTextureData() # presence of correct alpha is plausible from this # (in testexpr_11pd2). By itself, it does make a difference (alpha 0 places are black in testexpr_11pd2, not blue # (probably a leaked color) like in testexpr_11pd1), but self.blend is also needed to make it translucent. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) return
def bind_texture(self, clamp = False, use_mipmaps = True, decal = False, pixmap = False): """ bind our texture, and set texture-related GL params as specified. Anything that calls this should eventually call self.kluge_reset_texture_mode_to_work_around_renderText_bug(), but only after all drawing using the texture is done. """ # Notes [some of this belongs in docstring]: #e - we might want to pass these tex params as one chunk, or a flags word #e - we might want to optim for when they don't change # - most of them have default values like the old code had implicitly, but not pixmap, which old code had as implicitly true # - pixmap is misnamed, it doesn't use the pixmap ops, tho we might like to use those from the same image data someday have_mipmaps, tex_name = self.loaded_texture_data ## texture_helpers.setup_to_draw_texture_name(have_mipmaps, tex_name) # let's inline that instead, including its call of _initTextureEnv, and then modify it [061126] glBindTexture(GL_TEXTURE_2D, tex_name) # modified from _initTextureEnv(have_mipmaps) in texture_helpers.py if clamp: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) if not pixmap: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) if have_mipmaps and use_mipmaps: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) if decal: glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) else: # see red book p410-411 -- can use GL_DECAL, GL_REPLACE, GL_MODULATE, GL_BLEND, GL_ADD, GL_COMBINE. # (Except that I can't import GL_COMBINE (iMac G5) so maybe it's not always available.) # GL_DECAL leaves fragment alpha unchanged and uses texture alpha to mix its color with fragment color # (fragment data comes from the polygon's alpha & color as if drawn untextured). # GL_REPLACE just discards fragment data in favor of texture data incl alpha -- that would be a better default. # [later 070404: now it is the default.] # Eventually permit all these values -- for now just let decal = False mean GL_REPLACE. [070403] # ## print "getTextureData", self, self._image.getTextureData() # presence of correct alpha is plausible from this # (in testexpr_11pd2). By itself, it does make a difference (alpha 0 places are black in testexpr_11pd2, not blue # (probably a leaked color) like in testexpr_11pd1), but self.blend is also needed to make it translucent. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) return
def kluge_reset_texture_mode_to_work_around_renderText_bug(self): """ This helps work around a renderText bug in Qt 4.3.x (fixed in Qt 4.4.0). It should be called after anything which might set GL_TEXTURE_ENV_MODE to something other than GL_MODULATE (e.g. after drawing an ESP Image, or textures used in testmode), and before drawing the main model or when initializing the graphics context. """ #bruce 081205 made this a separate method, called it from more places. # for more info, see: # http://trolltech.com/developer/task-tracker/index_html?method=entry&id=183995 # http://trolltech.com/developer/changes/changes-4.4.0 (issue 183995) # http://www.nanoengineer-1.net/mediawiki/index.php?title=Qt_bugs_in_renderText#glTexEnvf_turns_all_renderText_characters_into_solid_rectangles # In theory this should no longer be needed once we upgrade to Qt 4.4.0. # # piotr 080620 - fixed "white text" bug when using Qt 4.3.x # [by doing this inline in clear_and_draw_background] -- # before rendering text, the texture mode should be set to GL_MODULATE # to reflect current color changes. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
def load_texture(image): image = limit_pixels_count(image, args.pixels_limit) width, height = image.size image = image.tostring("raw", "RGBX", 0, -1) # Create Texture _id = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, _id) glPixelStorei(GL_UNPACK_ALIGNMENT, 1) glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) return _id
def load_texture(image): image = limit_pixels_count(image, args.pixels_limit) width, height = image.size image = image.tostring("raw", "RGBX", 0, -1) # Create Texture _id = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, _id) glPixelStorei(GL_UNPACK_ALIGNMENT, 1) glTexImage2D( GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image ) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) return _id
def _initTextureEnv(self): # called during draw method glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) # [looks like a bug that we overwrite clamp with repeat, just # below? bruce 060212 comment] glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) if debug_pref("smoother textures", Choice_boolean_False, prefs_key = True): #bruce 060212 new feature (only visible in debug version so far); # ideally it'd be controllable per-jig for side-by-side comparison; # also, changing its menu item ought to gl_update but doesn't ##e glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) if self.have_mipmaps: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) else: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) return
def drawHeightfield(color, w, h, textureReady, opacity, SOLID=False, pickCheckOnly=False, hf=None): """ Draw a heighfield using vertex and normal arrays. Optionally, it could be texuture mapped. @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick selection purpose. """ from OpenGL.GL import glTexEnvf from OpenGL.GL import GL_TEXTURE_ENV from OpenGL.GL import GL_TEXTURE_ENV_MODE from OpenGL.GL import GL_MODULATE from OpenGL.GL import glVertexPointer from OpenGL.GL import glNormalPointer from OpenGL.GL import glTexCoordPointer from OpenGL.GL import glDrawArrays from OpenGL.GL import glEnableClientState from OpenGL.GL import GL_VERTEX_ARRAY from OpenGL.GL import GL_NORMAL_ARRAY from OpenGL.GL import GL_TEXTURE_COORD_ARRAY glEnable(GL_COLOR_MATERIAL) glEnable(GL_LIGHTING) ### glColor4fv(list(color) + [opacity]) ### glColor3fv(list(color)) glColor3f(1.0, 1.0, 1.0) glPushMatrix() glScalef(w, h, 1.0) if SOLID: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) else: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glDisable(GL_CULL_FACE) if not pickCheckOnly: glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) if textureReady: glEnable(GL_TEXTURE_2D) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glEnableClientState(GL_TEXTURE_COORD_ARRAY) for tstrip_vert, tstrip_norm, tstrip_tex in hf: glVertexPointer(3, GL_FLOAT, 0, tstrip_vert) glNormalPointer(GL_FLOAT, 0, tstrip_norm) glTexCoordPointer(2, GL_FLOAT, 0, tstrip_tex) glDrawArrays(GL_TRIANGLE_STRIP, 0, len(tstrip_vert)) glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_NORMAL_ARRAY) glDisableClientState(GL_TEXTURE_COORD_ARRAY) glDisable(GL_COLOR_MATERIAL) if not pickCheckOnly: if textureReady: glDisable(GL_TEXTURE_2D) glDepthMask(GL_TRUE) glEnable(GL_CULL_FACE) if not SOLID: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) glPopMatrix() glEnable(GL_LIGHTING) return
def draw_mesh(m, lighting_on): # Supply vertices glEnableClientState(GL_VERTEX_ARRAY) m.vbo['v'].bind() glVertexPointer(3, GL_FLOAT, 0, m.vbo['v']) m.vbo['v'].unbind() # Supply normals if 'vn' in m.vbo.keys(): glEnableClientState(GL_NORMAL_ARRAY) m.vbo['vn'].bind() glNormalPointer(GL_FLOAT, 0, m.vbo['vn']) m.vbo['vn'].unbind() else: glDisableClientState(GL_NORMAL_ARRAY) # Supply colors if 'vc' in m.vbo.keys(): glEnableClientState(GL_COLOR_ARRAY) m.vbo['vc'].bind() glColorPointer(3, GL_FLOAT, 0, m.vbo['vc']) m.vbo['vc'].unbind() else: glDisableClientState(GL_COLOR_ARRAY) if ('vt' in m.vbo.keys()) and hasattr(m, 'textureID'): glEnable(GL_TEXTURE_2D) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) glBindTexture(GL_TEXTURE_2D, m.textureID) glEnableClientState(GL_TEXTURE_COORD_ARRAY) m.vbo['vt'].bind() glTexCoordPointer(2, GL_FLOAT, 0, m.vbo['vt']) m.vbo['vt'].unbind() else: glDisable(GL_TEXTURE_2D) glDisableClientState(GL_TEXTURE_COORD_ARRAY) # Draw if len(m.f) > 0: # ie if it is triangulated if lighting_on: glEnable(GL_LIGHTING) else: glDisable(GL_LIGHTING) glDrawElementsui(GL_TRIANGLES, np.arange(m.f.size, dtype=np.uint32)) else: # not triangulated, so disable lighting glDisable(GL_LIGHTING) glPointSize(2) glDrawElementsui(GL_POINTS, np.arange(len(m.v), dtype=np.uint32)) if hasattr(m, 'v_to_text'): glEnable(GL_TEXTURE_2D) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) # glEnable(GL_TEXTURE_GEN_S) # glEnable(GL_TEXTURE_GEN_T) # glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR) # glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR) bgcolor = np.array(glGetDoublev(GL_COLOR_CLEAR_VALUE)) fgcolor = 1. - bgcolor from .lines import Lines sc = float(np.max(np.max(m.v, axis=0) - np.min(m.v, axis=0))) / 10. cur_mtx = np.linalg.pinv(glGetFloatv(GL_MODELVIEW_MATRIX).T) xdir = cur_mtx[:3, 0] ydir = cur_mtx[:3, 1] glEnable(GL_LINE_SMOOTH) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) for vidx, text in m.v_to_text.items(): pos0 = m.v[vidx].copy() pos1 = m.v[vidx].copy() if hasattr(m, 'vn'): pos1 += m.vn[vidx] * sc glLineWidth(5.0) ln = Lines(v=np.vstack((pos0, pos1)), e=np.array([[0, 1]])) glEnable(GL_LIGHTING) glColor3f(1. - 0.8, 1. - 0.8, 1. - 1.00) MeshViewerSingle.draw_lines(ln) glDisable(GL_LIGHTING) texture_id = get_textureid_with_text(text, bgcolor, fgcolor) glBindTexture(GL_TEXTURE_2D, texture_id) glPushMatrix() glTranslatef(pos1[0], pos1[1], pos1[2]) dx = xdir * .10 dy = ydir * .10 if False: glBegin(GL_QUADS) glTexCoord2f(1., 0.) glVertex3f(*(+dx + dy)) glTexCoord2f(1., 1.) glVertex3f(*(+dx - dy)) glTexCoord2f(0., 1.) glVertex3f(*(-dx - dy)) glTexCoord2f(0., 0.) glVertex3f(*(-dx + dy)) # gluSphere(quadratic,0.05,32,32) glEnd() else: glBegin(GL_POLYGON) for r in np.arange(0, np.pi * 2., .01): glTexCoord2f(np.cos(r) / 2. + .5, np.sin(r) / 2. + .5) glVertex3f(*(dx * np.cos(r) + -dy * np.sin(r))) glEnd() glPopMatrix()
def drawHeightfield(color, w, h, textureReady, opacity, SOLID = False, pickCheckOnly = False, hf = None): """ Draw a heighfield using vertex and normal arrays. Optionally, it could be texture mapped. @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick selection purpose. """ if not hf: # Return if heightfield is not provided return glEnable(GL_COLOR_MATERIAL) glEnable(GL_LIGHTING) # Don't use opacity, otherwise the heighfield polygons should be sorted # - something to implement later... ## glColor3v(list(color)) if textureReady: # For texturing, use white color (to be modulated by the texture) glColor3f(1,1,1) else: glColor3fv(list(color)) glPushMatrix() glScalef(w, h, 1.0) if SOLID: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) else: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glDisable(GL_CULL_FACE) if not pickCheckOnly: glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) if textureReady: glEnable(GL_TEXTURE_2D) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glEnableClientState(GL_TEXTURE_COORD_ARRAY) for tstrip_vert, tstrip_norm, tstrip_tex in hf: glVertexPointer(3, GL_FLOAT, 0, tstrip_vert) glNormalPointer(GL_FLOAT, 0, tstrip_norm) glTexCoordPointer(2, GL_FLOAT, 0, tstrip_tex) glDrawArrays(GL_TRIANGLE_STRIP, 0, len(tstrip_vert)) glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_NORMAL_ARRAY) glDisableClientState(GL_TEXTURE_COORD_ARRAY) glDisable(GL_COLOR_MATERIAL) if not pickCheckOnly: if textureReady: glDisable(GL_TEXTURE_2D) glDepthMask(GL_TRUE) glEnable(GL_CULL_FACE) if not SOLID: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) glPopMatrix() glEnable(GL_LIGHTING) return
def drawHeightfield(color, w, h, textureReady, opacity, SOLID=False, pickCheckOnly=False, hf=None): """ Draw a heighfield using vertex and normal arrays. Optionally, it could be texture mapped. @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick selection purpose. """ if not hf: # Return if heightfield is not provided return glEnable(GL_COLOR_MATERIAL) glEnable(GL_LIGHTING) # Don't use opacity, otherwise the heighfield polygons should be sorted # - something to implement later... ## glColor3v(list(color)) if textureReady: # For texturing, use white color (to be modulated by the texture) glColor3f(1, 1, 1) else: glColor3fv(list(color)) glPushMatrix() glScalef(w, h, 1.0) if SOLID: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) else: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glDisable(GL_CULL_FACE) if not pickCheckOnly: glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) if textureReady: glEnable(GL_TEXTURE_2D) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glEnableClientState(GL_TEXTURE_COORD_ARRAY) for tstrip_vert, tstrip_norm, tstrip_tex in hf: glVertexPointer(3, GL_FLOAT, 0, tstrip_vert) glNormalPointer(GL_FLOAT, 0, tstrip_norm) glTexCoordPointer(2, GL_FLOAT, 0, tstrip_tex) glDrawArrays(GL_TRIANGLE_STRIP, 0, len(tstrip_vert)) glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_NORMAL_ARRAY) glDisableClientState(GL_TEXTURE_COORD_ARRAY) glDisable(GL_COLOR_MATERIAL) if not pickCheckOnly: if textureReady: glDisable(GL_TEXTURE_2D) glDepthMask(GL_TRUE) glEnable(GL_CULL_FACE) if not SOLID: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) glPopMatrix() glEnable(GL_LIGHTING) return