def render_routine():
    global render_time_list
    global render_left
    global render_right

    gl.glFinish()
    ti = time.time()

    #prepare rendering model
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
    glu.gluOrtho2D(*screen_limits)

    # translate to position of left board and render
    gl.glTranslatef(xTranslateLeft, yTranslate, 0.0)
    if render_left:
        CB_left.render()
        render_left = False

    # translate to position of right board and render
    gl.glTranslatef(-xTranslateLeft + xTranslateRight, 0.0, 0.0)
    if render_right:
        CB_right.render()
        render_right = False

    #show the scene
    gl.glFinish()
    glut.glutSwapBuffers()

    # get time for later mean frame time calculation
    gl.glFinish()
    tf = time.time()
    render_time_list.append(tf - ti)
예제 #2
0
파일: Opengl.py 프로젝트: davidsoncolin/IMS
 def render(self, tid):
     # render the movie texture with the x2ds into the texture coords in the buffer
     x2ds = np.array(self.x2ds[self.vs_mapping], dtype=np.float32)
     GL.glClearColor(0, 0, 0, 1)
     GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
     GL.glShadeModel(GL.GL_FLAT)
     GL.glDisable(GL.GL_LIGHTING)
     GL.glEnable(GL.GL_TEXTURE_2D)
     GL.glBindTexture(GL.GL_TEXTURE_2D, tid)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     GL.glMatrixMode(GL.GL_MODELVIEW)
     GL.glLoadIdentity()
     GLU.gluOrtho2D(0, 1, 0, 1)  # (0,0) at bottom-left
     GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
     self.vts.bind()
     GL.glVertexPointerf(self.vts)
     GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY)
     v = vbo.VBO(x2ds, usage='GL_STATIC_DRAW_ARB')
     v.bind()
     GL.glTexCoordPointerf(v)
     self.tris.bind()
     GL.glDrawElementsui(GL.GL_TRIANGLES, self.tris)
     self.tris.unbind()
     v.unbind()
     self.vts.unbind()
예제 #3
0
def render_routine():
    global render_time_list

    # gl.glFinish()
    # t_initial = time.time()

    #prepare rendering model
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
    glu.gluOrtho2D(*screen_limits)

    # translate to position of left board and render
    gl.glTranslatef(xTranslateLeft, yTranslate, 0.0)
    CB_left.render()

    # translate to position of right board and render
    gl.glTranslatef(-xTranslateLeft + xTranslateRight, 0.0, 0.0)
    CB_right.render()

    #show the scene
    gl.glFinish()
    glut.glutSwapBuffers()

    gl.glFinish()
    t_final = time.time()
    render_time_list.append(t_final)#t_final - t_initial)
 def resizeGL(self, w, h):
     GL.glViewport(0, 0, w, h)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     # 軸幅の設定
     xmin, xmax, ymin, ymax = self._get_axes()
     GLU.gluOrtho2D(xmin, xmax, ymin, ymax)
예제 #5
0
    def gl_draw_all(self, root, offset):
        if not self.visible:
            return
        from OpenGL import GL, GLU

        rect = self.rect.move(offset)
        if self.is_gl_container:
            self.gl_draw_self(root, offset)
            suboffset = rect.topleft
            for subwidget in self.subwidgets:
                subwidget.gl_draw_all(root, suboffset)
        else:
            try:
                surface = Surface(self.size, SRCALPHA)
            except Exception:
                #size error?
                return
            self.draw_all(surface)
            data = image.tostring(surface, 'RGBA', 1)
            w, h = root.size
            GL.glViewport(0, 0, w, h)
            GL.glMatrixMode(GL.GL_PROJECTION)
            GL.glLoadIdentity()
            GLU.gluOrtho2D(0, w, 0, h)
            GL.glMatrixMode(GL.GL_MODELVIEW)
            GL.glLoadIdentity()
            GL.glRasterPos2i(max(rect.left, 0), max(h - rect.bottom, 0))
            GL.glPushAttrib(GL.GL_COLOR_BUFFER_BIT)
            GL.glEnable(GL.GL_BLEND)
            GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
            GL.glDrawPixels(self.width, self.height, GL.GL_RGBA,
                            GL.GL_UNSIGNED_BYTE, fromstring(data,
                                                            dtype='uint8'))
            GL.glPopAttrib()
            GL.glFlush()
예제 #6
0
    def onRender(self):
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45, self.width / self.height, 0.01, 80.0)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        gl.glTranslated(0.0, 0.0, -self.camPosZ)  # apply camera zooming
        gl.glRotated(self.angleY, 0.0, 1.0, 0.0)  # apply camera rotation

        # draw particles
        for system in self.systems:
            system.render()

        # draw texts(F1 key)
        if not notext and self.text != 0:
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluOrtho2D(0, self.width, 0, self.height)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glColor3d(1.0, 1.0, 1.0)
            if self.text == 2:
                self.drawText(self.nbParticles, 4.0, 40.0)
            self.drawText(self.fps, 4.0, 8.0)

        # refresh
        sdl2.SDL_GL_SwapWindow(self.window)
예제 #7
0
 def resizeGL(self, w, h):
     GL.glViewport(0, 0, w, h)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     GLU.gluOrtho2D(0, w, h, 0)  # same OpenGL coordinates as pixel ones
     GL.glMatrixMode(GL.GL_MODELVIEW)
     GL.glLoadIdentity()
예제 #8
0
 def resizeGL(self, w, h):
     self.width, self.height = w, h
     GL.glViewport(0, 0, w, h)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     GLU.gluOrtho2D(0, self.width, 0, self.height)
     GL.glMatrixMode(GL.GL_MODELVIEW)
예제 #9
0
	def drawMarquee(self, x0, y0, x1, y1):
		GL.glMatrixMode(GL.GL_MODELVIEW)
		GL.glPushMatrix()
		GL.glLoadIdentity()
		GL.glMatrixMode(GL.GL_PROJECTION)
		GL.glPushMatrix()
		GL.glLoadIdentity()
		GLU.gluOrtho2D(0.0, self.width, 0.0, self.height) # (0,0) at bottom-left
		GL.glLineStipple(1, 0x5555)
		GL.glLineWidth(1.0)
		GL.glEnable(GL.GL_LINE_STIPPLE)
		GL.glEnable(GL.GL_COLOR_LOGIC_OP)
		GL.glLogicOp(GL.GL_INVERT)
		GL.glTranslatef(0.375, 0.375, 0.0)
		GL.glColor3f(1,1,1)
		GL.glBegin(GL.GL_LINE_LOOP)
		GL.glVertex2i(x0,y0)
		GL.glVertex2i(x1,y0)
		GL.glVertex2i(x1,y1)
		GL.glVertex2i(x0,y1)
		GL.glEnd()
		GL.glMatrixMode(GL.GL_PROJECTION)
		GL.glPopMatrix()
		GL.glMatrixMode(GL.GL_MODELVIEW)
		GL.glPopMatrix()
		GL.glDisable(GL.GL_LINE_STIPPLE)
		GL.glDisable(GL.GL_COLOR_LOGIC_OP)
예제 #10
0
파일: widget.py 프로젝트: 18986064/mcedit
 def gl_draw_all(self, root, offset):
     if not self.visible:
         return
     from OpenGL import GL, GLU
     rect = self.rect.move(offset)
     if self.is_gl_container:
         self.gl_draw_self(root, offset)
         suboffset = rect.topleft
         for subwidget in self.subwidgets:
             subwidget.gl_draw_all(root, suboffset)
     else:
         try:
             surface = Surface(self.size, SRCALPHA)
         except Exception, e:
             #size error?
             return
         self.draw_all(surface)
         data = image.tostring(surface, 'RGBA', 1)
         w, h = root.size
         GL.glViewport(0, 0, w, h)
         GL.glMatrixMode(GL.GL_PROJECTION)
         GL.glLoadIdentity()
         GLU.gluOrtho2D(0, w, 0, h)
         GL.glMatrixMode(GL.GL_MODELVIEW)
         GL.glLoadIdentity()
         GL.glRasterPos2i(max(rect.left, 0), max(h - rect.bottom, 0))
         GL.glPushAttrib(GL.GL_COLOR_BUFFER_BIT)
         GL.glEnable(GL.GL_BLEND)
         GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
         GL.glDrawPixels(self.width, self.height,
             GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, fromstring(data, dtype='uint8'))
         GL.glPopAttrib()
         GL.glFlush()
예제 #11
0
	def gl_draw_all(self, root, offset):
		from OpenGL import GL, GLU
		rect = self.rect.move(offset)
		if self.is_gl_container:
			self.gl_draw_self(root, offset)
			suboffset = rect.topleft
			for subwidget in self.subwidgets:
				subwidget.gl_draw_all(root, suboffset)
		else:
			surface = Surface(self.size, SRCALPHA)
			self.draw_all(surface)
			data = image.tostring(surface, 'RGBA', 1)
			w, h = root.size
			GL.glViewport(0, 0, w, h)
			GL.glMatrixMode(GL.GL_PROJECTION)
			GL.glLoadIdentity()
			GLU.gluOrtho2D(0, w, 0, h)
			GL.glMatrixMode(GL.GL_MODELVIEW)
			GL.glLoadIdentity()
			GL.glRasterPos2i(rect.left, h - rect.bottom)
			GL.glPushAttrib(GL.GL_COLOR_BUFFER_BIT)
			GL.glEnable(GL.GL_BLEND)
			GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
			GL.glDrawPixels(self.width, self.height,
				GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, data)
			GL.glPopAttrib()
예제 #12
0
파일: window.py 프로젝트: rjaguar3/pygears
 def resizeGL(self, width, height):
     """Resize the OpenGL viewport to reflect the given window dimensions."""
     GL.glViewport(0, 0, width, height)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     GLU.gluOrtho2D(0, width, 0, height)
     GL.glMatrixMode(GL.GL_MODELVIEW)
     GL.glLoadIdentity()
예제 #13
0
 def set_screen(self):
     '''
     Set OpenGL projection matrix to Ortho2D, showing world space coords
     0 <= x < WIDTH, and 0 <= y < HEIGHT.
     '''
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     glu.gluOrtho2D(0, self.width - 1, 0, self.height - 1)
예제 #14
0
def init_gl():
    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glPushMatrix()
    gl.glLoadIdentity()
    glu.gluOrtho2D(0, 80, 60, 0)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glPushMatrix()
    gl.glLoadIdentity()
예제 #15
0
    def onRender(self):
        gl.glDepthMask(gl.GL_TRUE)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45, self.width / self.height, 0.01, 80.0)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        gl.glTranslated(0.0, 0.0, -self.camPosZ)  # apply camera zooming
        gl.glRotated(self.angleX, 1.0, 0.0, 0.0)  # apply camera rotation
        gl.glRotated(self.angleY, 0.0, 1.0, 0.0)

        # draw fountain
        if self.renderEnv:
            gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE,
                         gl.GL_MODULATE)
            gl.glCallList(self.DISPLAY_LIST_OBJECT)

            gl.glMatrixMode(gl.GL_TEXTURE)

            # scroll water texture
            angle = self.totalTime * 2.0 * math.pi / 12000.0
            sinA = math.sin(angle) * 0.2
            cosA = math.cos(angle) * 0.2

            gl.glRotatef(angle, 0.0, 0.0, 1.0)
            gl.glTranslatef(sinA, cosA, 1.0)
            gl.glScalef(1.0 + sinA * 0.2, 1.0 + cosA * 0.2, 1.0)

        # draw bounding box(F2 key)
        drawBoundingBox(self.group, 1.0, 0.0, 0.0)

        # draw fountain water
        if self.renderEnv:
            gl.glCallList(self.DISPLAY_LIST_WATER)
            gl.glLoadIdentity()

        # draw particles
        self.system.render()

        # draw texts(F1 key)
        if not notext and self.text != 0:
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluOrtho2D(0, self.width, 0, self.height)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glColor3d(1.0, 1.0, 1.0)
            if self.text == 2:
                self.drawText(self.nbParticles, 4.0, 40.0)
            self.drawText(self.fps, 4.0, 8.0)

        # refresh
        sdl2.SDL_GL_SwapWindow(self.window)
예제 #16
0
 def initializeGL(self):
     GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
     GL.glClearColor(0.1, 0.1, 0.15, 1.0)
     GL.glClearDepth(1.0)
     GL.glColor3ub(58, 90, 41)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     GLU.gluOrtho2D(0, self.width, 0, self.height)
     GL.glFlush()
예제 #17
0
파일: acacia.py 프로젝트: skykooler/Acacia
	def resizeGL(self, w, h):
		# GL.glViewport(0, 0, w, h)
		# GL.glMatrixMode(GL.GL_PROJECTION)
		# GL.glLoadIdentity()
		# x = float(w) / h
		# GL.glFrustum(-x, x, -1.0, 1.0, 1.0, 10.0)
		# GL.glMatrixMode(GL.GL_MODELVIEW)
		GL.glLoadIdentity()
		GLU.gluOrtho2D(0, w, 0, h);
예제 #18
0
def resize(w: int, h: int) -> None:
    gl.glViewport(0, 0, w, h)

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()

    glu.gluOrtho2D(-10, 10, -10, 10)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
예제 #19
0
def reshape(width,height):

	gl.glViewport(0, 0, width, height)
	glu.gluOrtho2D(0, width, 0, height)
	
	PROJ_MATRIX[0,0] = 2.0/width
	PROJ_MATRIX[1,1] = 2.0/height

	print ("Projection Matrix: \n", PROJ_MATRIX)
예제 #20
0
 def resizeGL(self, width, height):
     # //: means floor the divede result
     self.width=width
     self.height=height
     GL.glViewport(0, 0, width, height)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     GLU.gluOrtho2D(0,100,0,100);
     GL.glMatrixMode(GL.GL_MODELVIEW)
예제 #21
0
 def _setup_scene(self, *args):
     gl.glViewport(*args);
     gl.glMatrixMode(gl.GL_PROJECTION);
     gl.glLoadIdentity();
     glu.gluOrtho2D(0.0, 1.0, 0.0, 1.0);
     gl.glMatrixMode(gl.GL_MODELVIEW);
     gl.glLoadIdentity();
     
     gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
     gl.glEnable(gl.GL_BLEND)
예제 #22
0
 def resizeGL(self, width, height):
     if height == 0: height = 1
     glViewport(0, 0, width, height)
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity()
     aspect = width / float(height)
     GLU.gluOrtho2D(0, width, height, 0);
     #GLU.gluPerspective(45.0, aspect, 1.0, 100.0)
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
예제 #23
0
 def initgl(self):
     GL.glViewport(0, 0, self.width, self.height)
     GL.glClearColor(1.0, 1.0, 1.0, 0.0)
     GL.glColor3f(0.0, 0.0, 0.0)
     GL.glPointSize(4.0)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     GLU.gluOrtho2D(-5, 5, -5, 5)
     self.start = time.time()
     self.nframes = 0
예제 #24
0
    def onRender(self):
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45, self.width / self.height, 0.01, 80.0)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        gl.glTranslated(0.0, 0.0, -self.camPosZ)  # apply camera zooming
        gl.glRotated(self.angleX, 1.0, 0.0, 0.0)  # apply camera rotation
        gl.glRotated(self.angleY, 0.0, 1.0, 0.0)

        # draw obstacles
        if self.renderEnv:
            gl.glDisable(gl.GL_BLEND)
            gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE,
                         gl.GL_MODULATE)
            gl.glCallList(self.DISPLAY_LIST_WORLD)

        # draw bounding box(F2 key)
        drawBoundingBox(self.group, 1.0, 0.0, 0.0)

        # draw outlines of the boxes(F6 key)
        if self.enableBoxDrawing:
            for box in self.boxes:  # blue for crates
                drawBox(box.getPosition() - box.getDimension() * 0.5,
                        box.getPosition() + box.getDimension() * 0.5, 0.0, 0.0,
                        1.0)
            for box in self.partitions:  # green for partitions
                drawBox(box.getPosition() - box.getDimension() * 0.5,
                        box.getPosition() + box.getDimension() * 0.5, 0.0, 1.0,
                        0.0)

        # draw particles
        gl.glDisable(gl.GL_LIGHTING)
        self.system.render()

        # draw texts(F1 key)
        if not notext and self.text != 0:
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluOrtho2D(0, self.width, 0, self.height)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glColor3d(1.0, 1.0, 1.0)
            if self.text == 2:
                self.drawText(self.nbParticles, 4.0, 40.0)
            self.drawText(self.fps, 4.0, 8.0)

        # refresh
        sdl2.SDL_GL_SwapWindow(self.window)
def setupWindow():
    ''' Initializes pygame and configures window and camera parameters. '''
    pygame.init()
    display = (DIMENSIONS[0], DIMENSIONS[1])
    pygame.display.set_caption("OpenGL Fractals")
    pygame.display.set_mode(display, DOUBLEBUF | OPENGL)

    glu.gluOrtho2D(-1, 1, -1, 1)
    gl.glViewport(0, 0, DIMENSIONS[0], DIMENSIONS[1])

    gl.glClearColor(0.0, 0.0, 0.0, 1.0)
예제 #26
0
    def show_loading_screen(self):
        # Projection

        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GLU.gluOrtho2D(0, self.width, 0, self.height)

        # Camera

        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glLoadIdentity()

        GL.glDisable(GL.GL_DEPTH_TEST)

        GL.glEnable(GL.GL_BLEND)

        cx = 9
        cy = 15
        ly = int(cy * 1.25)

        message = f"Analysing model..."
        width = cx * len(message)

        x = self.width / 2 - width / 2
        y = ly * 2.5
        margin = 12

        GL.glColor3f(0.12, 0.12, 0.12)

        x1 = x - 2
        y1 = y - 3
        x2 = x1 + width
        y2 = y1 + cy
        x0 = x1 - margin
        y0 = y1 - margin / 2
        x3 = x2 + margin
        y3 = y2 + margin / 2

        GL.glBegin(GL.GL_POLYGON)
        GL.glVertex2f(x0, y1)
        GL.glVertex2f(x1, y0)
        GL.glVertex2f(x2, y0)
        GL.glVertex2f(x3, y1)
        GL.glVertex2f(x3, y2)
        GL.glVertex2f(x2, y3)
        GL.glVertex2f(x1, y3)
        GL.glVertex2f(x0, y2)
        GL.glEnd()

        GL.glColor4f(0.8, 0.8, 0.8, 1)
        self.text(x, y, message)

        GLUT.glutSwapBuffers()
예제 #27
0
파일: client.py 프로젝트: Reepca/YAHRP
def run():
	if SDL_Init(SDL_INIT_VIDEO) != 0:
		print(SDL_GetError())
		return -1

	window = SDL_CreateWindow(b"OpenGL Test",
							  SDL_WINDOWPOS_UNDEFINED,
							  SDL_WINDOWPOS_UNDEFINED, 800, 600,
							  SDL_WINDOW_OPENGL)
	
	if not window:
		print(SDL_GetError())
		return -1

	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2)
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1)
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
    					SDL_GL_CONTEXT_PROFILE_CORE)
	context = SDL_GL_CreateContext(window)

	event = SDL_Event()
	running = True
	while running:
		while SDL_PollEvent(ctypes.byref(event)) != 0:
			if event.type == SDL_QUIT:
				running = False

		GL.glClearColor(0, 0, 0, 1)
		GL.glClear(GL.GL_COLOR_BUFFER_BIT)
		GL.glColor3f(0, 1, 1)
		GL.glMatrixMode(GL.GL_PROJECTION)
		GL.glLoadIdentity()
		GLU.gluOrtho2D(0, 800, 0, 600)
		GL.glMatrixMode(GL.GL_MODELVIEW)
		
		GL.glPushMatrix()
		GL.glTranslatef(25, 25, 0)
		#GLUT.glutWireSphere(25, 1000, 10)
		#GL.glBegin(GL.GL_LINES)
		#GL.glVertex2i(0, 0)
		#GL.glVertex2i(0, 50)
		#GL.glEnd()
		GL.glPopMatrix()
		GL.glFlush()


		SDL_GL_SwapWindow(window)
		SDL_Delay(10)

	SDL_GL_DeleteContext(context)
	SDL_DestroyWindow(window)
	SDL_Quit()
	return 0
예제 #28
0
 def setup_scene(self, *args):
     """ Set viewport (with args) and projection matrices.
     """
     gl.glViewport(*args);
     gl.glMatrixMode(gl.GL_PROJECTION);
     gl.glLoadIdentity();
     glu.gluOrtho2D(0.0, 1.0, 0.0, 1.0);
     gl.glMatrixMode(gl.GL_MODELVIEW);
     gl.glLoadIdentity();
     
     gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
     gl.glEnable(gl.GL_BLEND)
예제 #29
0
 def paintGL(self):
     GL.glClearColor(1.0, 1.0, 1.0, 0.0)             #白颜色
     GL.glClear(GL.GL_COLOR_BUFFER_BIT)       
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     GLU.gluOrtho2D(-20.0, 530.0, -50.0, 600.0)      #左下角右上角x左下角右上角y
     
     GL.glMatrixMode(GL.GL_MODELVIEW)
     GL.glLoadIdentity()
     self.myline1()                                  #画方框        
     if myfinish:
         self.mypb()                                 #画线
예제 #30
0
    def setup_scene(self, *args):
        """ Set viewport (with args) and projection matrices.
        """
        gl.glViewport(*args)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluOrtho2D(0.0, 1.0, 0.0, 1.0)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glEnable(gl.GL_BLEND)
예제 #31
0
    def display(self):
        """(Re)display all the actors in the scene.

        This should e.g. be used when actors are added to the scene,
        or after changing  camera position/orientation or lens.
        """
        #GD.debug("REDISPLAY CURRENT OPENGL CANVAS")
        self.makeCurrent()
        self.clear()
        glLight(self.lighting)
        # Draw Scene Actors
        # GD.debug("%s / %s" % (len(self.actors),len(self.annotations)))
        self.camera.loadProjection()
        self.camera.loadMatrix()
        if self.alphablend:
            opaque = [ a for a in self.actors if not a.trans ]
            transp = [ a for a in self.actors if a.trans ]
            for actor in opaque:
               actor.draw(mode=self.rendermode)
            GL.glEnable (GL.GL_BLEND)
            GL.glDepthMask (GL.GL_FALSE)
            GL.glBlendFunc (GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
            for actor in transp:
                actor.draw(mode=self.rendermode)
            GL.glDepthMask (GL.GL_TRUE)
            GL.glDisable (GL.GL_BLEND)
        else:
            for actor in self.actors:
                self.setDefaults()
                actor.draw(mode=self.rendermode)

        for actor in self.annotations:
            self.setDefaults()
            actor.draw(mode=self.rendermode)

        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        # Plot viewport decorations
        GL.glLoadIdentity()
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GLU.gluOrtho2D(0,self.width(),0,self.height())
        for actor in self.decorations:
            self.setDefaults()
            actor.draw(mode=self.rendermode)
        # end plot viewport decorations
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPopMatrix()
##         # Display angles
##         self.camera.getCurrentAngles()
        # make sure canvas is updated
        GL.glFlush()
예제 #32
0
    def paintGL(self):
        GL.glClearColor(1.0, 1.0, 1.0, 0.0)             #白颜色
        GL.glClear(GL.GL_COLOR_BUFFER_BIT)       
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GLU.gluOrtho2D(-20.0, 530.0, -20.0, 280.0)      #左下角右上角x左下角右上角y
        
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glLoadIdentity()
        GL.glPointSize(5.0)                             #点大小设置

        self.myline1()                                  #画方框
        self.mypp1()                                    #选择点
        if myfinish and myn:
            self.mypp2()                                #画线
예제 #33
0
def display():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()

    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    gl.glViewport(0, 0, int(RESOLUTION.x), int(RESOLUTION.y))
    glu.gluOrtho2D(0, int(RESOLUTION.x), int(RESOLUTION.y), 0)

    world.draw()

    pygame.display.flip()
예제 #34
0
 def gl_enter(self):
     r = self.rect
     w = r.width
     h = r.height
     gl = GL
     win_height = self.display.get_height()
     gl.glViewport(r.left, win_height - r.bottom, r.width, r.height)
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     GLU.gluOrtho2D(0, w, h, 0)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glEnable(gl.GL_BLEND)
     gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
예제 #35
0
    def begin_2D_drawing(self):
        """Set up the canvas for 2D drawing on top of 3D canvas.

        The 2D drawing operation should be ended by calling end_2D_drawing. 
        It is assumed that you will not try to change/refresh the normal
        3D drawing cycle during this operation.
        """
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        GL.glLoadIdentity()
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GLU.gluOrtho2D(0,self.width(),0,self.height())
        GL.glDisable(GL.GL_DEPTH_TEST)
        self.glLight(False)
        self.mode2D = True
예제 #36
0
파일: opengl.py 프로젝트: wolmir/cristina
	def gl_enter(self):
		r = self.rect
		w = r.width
		h = r.height
		gl = GL
		win_height = self.display.get_height()
		gl.glViewport(r.left, win_height - r.bottom, r.width, r.height)
		gl.glMatrixMode(gl.GL_PROJECTION)
		gl.glLoadIdentity()
		GLU.gluOrtho2D(0, w, h, 0)
		gl.glMatrixMode(gl.GL_MODELVIEW)
		gl.glLoadIdentity()
		gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)
		gl.glDisable(gl.GL_DEPTH_TEST)
		gl.glEnable(gl.GL_BLEND)
		gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
예제 #37
0
    def glinit(self):
        self._sock_thread = threading.Thread(target=self._comm_thread,args=(self,))
        self._sock_thread.start()
        
        GLUT.glutInit()
        GLUT.glutSetOption(GLUT.GLUT_ACTION_ON_WINDOW_CLOSE,
                           GLUT.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
        # Some window attributes
        GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE)
        GLUT.glutInitWindowSize(self._width, self._height)
        GLUT.glutInitWindowPosition(0, 0)
        self._win = GLUT.glutCreateWindow(self.title)

        # OpenGL callbacks
        GLUT.glutDisplayFunc(self._draw(self._render_func))
        GLUT.glutKeyboardFunc(self._on_key)
        GLUT.glutMouseFunc(self._on_click)
        GLUT.glutMotionFunc(self._on_mouse_motion)
        GLUT.glutCloseFunc(self._on_exit)
        GLUT.glutTimerFunc(self.refresh, self._timer, self.refresh)

        #set up 2d or 3d viewport in nice orthographic projection
        GL.glViewport(0, 0, self._width, self._height)
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        if self._dim==3:
            GL.glOrtho(-1.,1.,-1,1.,-1000.,1000.)
            GL.glMatrixMode(GL.GL_MODELVIEW)
        else:
            GL.glMatrixMode(GL.GL_PROJECTION)
            GL.glLoadIdentity()
            GLU.gluOrtho2D(-1.,1.,-1.,1.)
        #smooth the crap out of everything
        GL.glEnable(GL.GL_POINT_SMOOTH)
        GL.glEnable(GL.GL_LINE_SMOOTH)
        GL.glEnable(GL.GL_POLYGON_SMOOTH)
        GL.glEnable(GL.GL_BLEND)
        GL.glBlendFunc(GL.GL_ONE,GL.GL_ONE_MINUS_SRC_ALPHA)
        GL.glHint(GL.GL_LINE_SMOOTH_HINT,GL.GL_NICEST)
        GL.glHint(GL.GL_POINT_SMOOTH_HINT,GL.GL_NICEST)
        GL.glHint(GL.GL_POLYGON_SMOOTH_HINT,GL.GL_NICEST)

        #Clear Everything and call the main loop
        GL.glClearColor(*self.background_color)
        self._window_open =True
        GLUT.glutMainLoop()
예제 #38
0
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.shader = None

        self.triangleShadeProgram = None
        self.triangleBlueShadeProgram = None

        self.prepareGLUT()
        self.init()

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluOrtho2D(0, 1, 0, 1)
        # glu.gluOrtho2D(0, self.width, 0, self.height)

        glut.glutMainLoop()
예제 #39
0
    def display(self):
        """(Re)display all the actors in the scene.

        This should e.g. be used when actors are added to the scene,
        or after changing  camera position/orientation or lens.
        """
        self.clear()
        # Draw Scene Actors
        # GD.debug("%s / %s" % (len(self.actors),len(self.annotations)))
        self.camera.loadProjection()
        self.camera.loadMatrix()
        if self.alphablend:
            opaque = [ a for a in self.actors if not a.trans ]
            transp = [ a for a in self.actors if a.trans ]
            for actor in opaque:
               GL.glCallList(actor.list)
            GL.glEnable (GL.GL_BLEND)
            GL.glDepthMask (GL.GL_FALSE)
            GL.glBlendFunc (GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
            for actor in transp:
                GL.glCallList(actor.list)
            GL.glDepthMask (GL.GL_TRUE)
            GL.glDisable (GL.GL_BLEND)
        else:
            for actor in self.actors:
                GL.glCallList(actor.list)

        for actor in self.annotations:
            GL.glCallList(actor.list)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        # Plot viewport decorations
        GL.glLoadIdentity()
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GLU.gluOrtho2D(0,self.width(),0,self.height())
        for actor in self.decorations:
            GL.glCallList(actor.list)
        # end plot viewport decorations
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPopMatrix()
##         # Display angles
##         self.camera.getCurrentAngles()
        # ADDED TO MAKE SURE SCENE IS UPTODATE
        GL.glFlush()
예제 #40
0
    def start_rendering(self):
        #gl.glShadeModel(gl.GL_SMOOTH)
        r,g,b = self.background_color
        gl.glClearColor(r,g,b,1.0)
        gl.glClearDepth(1.0)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT )
        gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)
        gl.glDisable(gl.GL_DEPTH_TEST)

        #configure the display perspective
        # Fill the entire graphics window!
        gl.glViewport(0, 0, self.screen_width, self.screen_height)
        # Set the projection matrix... our "view"
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        #project to a 2D perspective
        glu.gluOrtho2D(self.screen_left, self.screen_right, self.screen_bottom, self.screen_top)
        self.ready_to_render = True
예제 #41
0
파일: main.py 프로젝트: yarolig/no_way_back
    def draw(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        if self.active_menu:
            GL.glClearColor(0.5, 0.6, 0.7, 1.0)
        else:
            GL.glClearColor(0.3, 0.4, 0.9, 1.0)

        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glLoadIdentity()
        w, h = self.get_screen_size()
        GLU.gluOrtho2D(0, w, 0, h)
        if self.active_menu:
            self.active_menu.draw()
        elif self.game:
            self.game.draw()

        pygame.display.flip()
예제 #42
0
  def HudMode(self, flag):
    if flag:
      # 2d projection
      OGL.glMatrixMode(OGL.GL_PROJECTION)
      OGL.glPushMatrix()
      OGL.glLoadIdentity()

      OGLU.gluOrtho2D(0, SCREEN_SIZE[0], 0, SCREEN_SIZE[1])
      OGL.glMatrixMode(OGL.GL_MODELVIEW)
      OGL.glPushMatrix()
      OGL.glLoadIdentity()
      OGL.glDisable(OGL.GL_DEPTH_TEST)
    else:
      # 3d projection
      OGL.glMatrixMode(OGL.GL_PROJECTION)
      OGL.glPopMatrix()
      OGL.glMatrixMode(OGL.GL_MODELVIEW)
      OGL.glPopMatrix()
      OGL.glEnable(OGL.GL_DEPTH_TEST)
예제 #43
0
    def load(self):
        gl.glViewport(self.offset[0], self.offset[1], self.size[0],
                      self.size[1])
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        x, y = self.size[0] / 2, self.size[1] / 2
        glu.gluOrtho2D(-x, x, y, -y)
        gl.glMatrixMode(gl.GL_MODELVIEW)

        gl.glLoadIdentity()
        gl.glColor3ub(255, 255, 255)
        gl.glBegin(gl.GL_TRIANGLE_FAN)
        gl.glVertex2f(-x, -y)
        gl.glVertex2f(x, -y)
        gl.glVertex2f(x, y)
        gl.glVertex2f(-x, y)
        gl.glEnd()

        gl.glTranslatef(*(-self.pos), 0)
예제 #44
0
def gl_ortho(width, height):
    """
    Context manager for enabling 2D orthographic projection.

    Parameters
    ----------
    width : int
        The width of the viewing region.
    height : int
        The height of the viewing region.

    """
    with new_matrix(gl.GL_PROJECTION, gl.GL_MODELVIEW):
        gl.glLoadIdentity()
        glu.gluOrtho2D(-width / 2, width / 2, -height / 2, height / 2)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        with new_matrix(gl.GL_MODELVIEW, gl.GL_PROJECTION):
            gl.glLoadIdentity()
            yield
예제 #45
0
    def _renderScreenObjects(self):
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glPushMatrix()
        GL.glLoadIdentity()
        GLU.gluOrtho2D(0,self.width,0,self.height)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        GL.glLoadIdentity()
        GL.glPushAttrib(GL_ENABLE_BIT)
        GL.glDisable(GL_LIGHTING);
        GL.glDisable(GL_DEPTH_TEST);

        for o in self.screenObjects:
            o.draw(self) # pass renderer so screen parameters are available

        GL.glPopAttrib() # GL_ENABLE_BIT
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPopMatrix()
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glPopMatrix()
예제 #46
0
    def _setOrthogonally(self):
        """
        Set the camera mode orthogonally.
        The z-axis gets effectively cut
        and no peception of perspective
        between multiple entities remains.

        :returns: None
        :rtype: None

        """
        trace('set camera mode orthogonally')

        # apply scale by using the camera's offset
        # and scale based on the smallest side
        o, r = self.offset, self.asprat
        horiz, vert = (r * o, o) if r > 1 else (o, o / r)

        glu.gluOrtho2D(-horiz, horiz, -vert, vert)
        self.translation = 0.
예제 #47
0
    def _renderScreenObjects(self):
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glPushMatrix()
        GL.glLoadIdentity()
        GLU.gluOrtho2D(0, self.width, 0, self.height)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        GL.glLoadIdentity()
        GL.glPushAttrib(GL_ENABLE_BIT)
        GL.glDisable(GL_LIGHTING)
        GL.glDisable(GL_DEPTH_TEST)

        for o in self.screenObjects:
            o.draw(self)  # pass renderer so screen parameters are available

        GL.glPopAttrib()  # GL_ENABLE_BIT
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPopMatrix()
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glPopMatrix()
예제 #48
0
    def setupView(self, client_width, client_height):
        """This function does the actual work to setup the window so we can 
        draw in it.  Most of its task is going to be sizing the Viewport to
        maintain aspect ratio and sizing the World Window to achieve the 
        maximum possible zoom.
        
        """
        
        world_height, world_width = self.world.getHeightWidth()
        
        #The ratio of the width to the height in the client-area
        screenratio = float(client_width) / float(client_height)
        
        ratio = float(world_width) / float(world_height)

        if ratio >= screenratio:
        
            self.viewport_left = 0
            self.viewport_bottom = int((client_height - (client_width / ratio)) / 2)
            self.viewport_width = client_width
            self.viewport_height = int(client_width / ratio)
            
            
        if ratio < screenratio:
        
            self.viewport_left = int((client_width - client_height * ratio) / 2)
            self.viewport_bottom = 0
            self.viewport_width = int(client_height * ratio)
            self.viewport_height = client_height
        
        self.viewport_right = self.viewport_left + self.viewport_width
        self.viewport_top = self.viewport_bottom + self.viewport_height
        
        GL.glViewport(self.viewport_left, 
                      self.viewport_bottom, 
                      self.viewport_width, 
                      self.viewport_height)
        
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GLU.gluOrtho2D(*self.world.getMaxLeftRightBottomTop())
예제 #49
0
파일: gl_windows.py 프로젝트: caosuomo/rads
 def glinit(self):
     #set up 2d or 3d viewport in nice orthographic projection
     GL.glViewport(0, 0, self.width, self.height)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     if self.dim==3:
         GL.glOrtho(-1.,1.,-1,1.,-1000.,1000.)
         GL.glMatrixMode(GL.GL_MODELVIEW)
     else:
         GL.glMatrixMode(GL.GL_PROJECTION)
         GL.glLoadIdentity()
         GLU.gluOrtho2D(-1.,1.,-1.,1.)
     #smooth the crap out of everything
     GL.glEnable(GL.GL_POINT_SMOOTH)
     GL.glEnable(GL.GL_LINE_SMOOTH)
     GL.glEnable(GL.GL_POLYGON_SMOOTH)
     GL.glEnable(GL.GL_BLEND)
     GL.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE_MINUS_SRC_ALPHA)
     GL.glHint(GL.GL_LINE_SMOOTH_HINT,GL.GL_NICEST)
     GL.glHint(GL.GL_POINT_SMOOTH_HINT,GL.GL_NICEST)
     GL.glHint(GL.GL_POLYGON_SMOOTH_HINT,GL.GL_NICEST)
예제 #50
0
파일: window.py 프로젝트: Nibba2018/gluppy
def init_window(display_callback, position=(200, 200), size=(500, 500),
                bg_color=(0, 0, 0, 1), draw_color=(1, 1, 1), point_size=4,
                ortho=(0, 500, 0, 500), title="pyOpenGL Window",
                mouse_callback=None):

    # Initialize GLUT
    glut.glutInit()
    # set Display mode
    glut.glutInitDisplayMode(glut.GLUT_SINGLE | glut.GLUT_RGB)
    glut.glutInitWindowSize(*size)
    glut.glutInitWindowPosition(*position)
    glut.glutCreateWindow(title)
    gl.glClearColor(*bg_color)        # Color to be filled after clearing.

    gl.glColor3f(*draw_color)         #  set the drawing color(white)
    gl.glPointSize(point_size)        # a 'dot' is 4 by 4 pixels
    glu.gluOrtho2D(*ortho)

    glut.glutMouseFunc(mouse_callback)
    glut.glutDisplayFunc(display_callback)  # Set display Callback
    glut.glutMainLoop()
예제 #51
0
def renderScene(programObj, width, height):
    """renderScene - the OpenGL commands to render our scene."""
    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    glu.gluOrtho2D(0, width, 0, height)
    gl.glViewport(0, 0, width, height)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
    gl.glUseProgram(programObj)
    # Draw one texture mapped quad in the (x,y) plane
    gl.glBegin(gl.GL_QUADS)
    gl.glTexCoord2f(0., 0.)
    gl.glVertex2f(0., 0.)
    gl.glTexCoord2f(1., 0.)
    gl.glVertex2f(float(width), 0.)
    gl.glTexCoord2f(1., 1.)
    gl.glVertex2f(float(width), float(height))
    gl.glTexCoord2f(0., 1.)
    gl.glVertex2f(0., float(height))
    gl.glEnd()
    gl.glUseProgram(0)
    checkGLError()
예제 #52
0
파일: galaxydemo.py 프로젝트: chromia/pyspk
    def onRender(self):
        gl.glDepthMask(gl.GL_TRUE)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45, self.width / self.height, 0.01, 33.0)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        gl.glTranslated(0.0, 0.0, -self.camPosZ)  # apply camera zooming
        gl.glRotated(self.angleX, 1.0, 0.0, 0.0)  # apply camera rotation
        gl.glRotated(self.angleY, 0.0, 1.0, 0.0)

        # draw particles
        self.galaxySystem.render()
        if self.renderEnv:
            self.starSystem.render()

        # draw bounding box(F2 key)
        gl.glDisable(gl.GL_BLEND)
        drawBoundingBox(self.galaxyGroup, 1.0, 0.0, 0.0)

        # draw texts(F1 key)
        if not notext and self.text != 0:
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluOrtho2D(0, self.width, 0, self.height)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glColor3d(1.0, 1.0, 1.0)
            if self.text == 2:
                self.drawText(self.nbParticles, 4.0, 40.0)
            self.drawText(self.fps, 4.0, 8.0)

        # refresh
        sdl2.SDL_GL_SwapWindow(self.window)
예제 #53
0
	def drawText(self, x, y, s, font=GLUT.GLUT_BITMAP_TIMES_ROMAN_10, color=None):
		if color is None: color = self.textColor
		if bool(GL.glWindowPos2f):
			GL.glColor3f(color[0],color[1],color[2])
			GL.glWindowPos2f(x, self.height-y)
			GLUT.glutBitmapString(font, s)
		else:
			GL.glDisable(GL.GL_TEXTURE_2D)
			GL.glColor3f(color[0],color[1],color[2])
			GL.glMatrixMode(GL.GL_MODELVIEW)
			GL.glPushMatrix()
			GL.glLoadIdentity()
			GL.glMatrixMode(GL.GL_PROJECTION)
			GL.glPushMatrix()
			GL.glLoadIdentity()
			GLU.gluOrtho2D(0.0, self.width, self.height, 0.0) # (0,0) at top-left
			GL.glRasterPos2f(x, y)
			GLUT.glutBitmapString(font, s)
			GL.glMatrixMode(GL.GL_PROJECTION)
			GL.glPopMatrix()
			GL.glMatrixMode(GL.GL_MODELVIEW)
			GL.glPopMatrix()
예제 #54
0
def renderScene(programObj, width, height):
    """renderScene - the OpenGL commands to render our scene."""
    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    glu.gluOrtho2D(0, width, 0, height)
    gl.glViewport(0, 0, width, height)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
    gl.glUseProgram(programObj)
    # Draw one texture mapped quad in the (x,y) plane
    gl.glBegin(gl.GL_QUADS)
    gl.glTexCoord2f(0., 0.)
    gl.glVertex2f(0., 0.)
    gl.glTexCoord2f(1., 0.)
    gl.glVertex2f(float(width), 0.)
    gl.glTexCoord2f(1., 1.)
    gl.glVertex2f(float(width), float(height))
    gl.glTexCoord2f(0., 1.)
    gl.glVertex2f(0., float(height))
    gl.glEnd()
    gl.glUseProgram(0)
    checkGLError()
예제 #55
0
    def display(self):
        """(Re)display all the actors in the scene.

        This should e.g. be used when actors are added to the scene,
        or after changing  camera position or lens.
        """
        self.clear()
        self.camera.loadProjection()
        self.camera.loadMatrix()
        for i in self.actors:
            GL.glCallList(i.list)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        # Plot viewport decorations
        GL.glLoadIdentity()
        GL.glMatrixMode (GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GLU.gluOrtho2D (0, self.width(), 0, self.height())
        for i in self.decorations:
            GL.glCallList(i.list)
        # end plot viewport decorations
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPopMatrix()
예제 #56
0
    def set_ortho(self, scale):
        '''
        Set OpenGL projection matrix to Ortho2D, such that the screen's
        shortest dimension (height on a landscape monitor or window) will show
        exactly `scale` of the world from the center of the screen to each
        edge, regardless of screen resolution or window size.
        '''
        def ortho_bounds(self, scale, aspect):
            left = bottom = -scale
            right = top = scale
            if self.width > self.height:
                # landscape mode window
                bottom /= aspect
                top /= aspect
            elif self.width < self.height:
                # portrait mode window
                left *= aspect
                right *= aspect
            return left, right, bottom, top

        aspect = self.width / self.height
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluOrtho2D(*ortho_bounds(scale, aspect))
예제 #57
0
파일: canvas.py 프로젝트: dladd/pyFormex
 def zoom_2D(self,zoom=None):
     if zoom is None:
         zoom = (0,self.width(),0,self.height())
     GLU.gluOrtho2D(*zoom)
예제 #58
0
    def reset(self, splash=None, caption=("", "")):
        pygame.key.set_repeat(500, 100)

        try:
            display.gl_set_attribute(pygame.GL_SWAP_CONTROL, config.settings.vsync.get())
        except Exception as e:
            logging.warning('Unable to set vertical sync: {0!r}'.format(e))

        display.gl_set_attribute(pygame.GL_ALPHA_SIZE, 8)

        if DEBUG_WM:
            print "config.settings.windowMaximized.get()", config.settings.windowMaximized.get()
        wwh = self.getWindowSize()
        if DEBUG_WM:
            print "wwh 1", wwh
        d = display.set_mode(wwh, self.displayMode())

        # Let initialize OpenGL stuff after the splash.
        GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
        GL.glAlphaFunc(GL.GL_NOTEQUAL, 0)
        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
 
        # textures are 256x256, so with this we can specify pixel coordinates
#        GL.glMatrixMode(GL.GL_TEXTURE)
#        GL.glScale(1 / 256., 1 / 256., 1 / 256.)

        display.set_caption(*caption)

        if mcplatform.WindowHandler:
            self.win = mcplatform.WindowHandler(mode=self.displayMode())

        # The following Windows specific code won't be executed if we're using '--debug-wm' switch.
        if not USE_WM and sys.platform == 'win32' and config.settings.setWindowPlacement.get():
            config.settings.setWindowPlacement.set(False)
            config.save()
            X, Y = config.settings.windowX.get(), config.settings.windowY.get()

            if X:
                hwndOwner = display.get_wm_info()['window']

                flags, showCmd, ptMin, ptMax, rect = mcplatform.win32gui.GetWindowPlacement(hwndOwner)
                realW = rect[2] - rect[0]
                realH = rect[3] - rect[1]

                showCmd = config.settings.windowShowCmd.get()
                rect = (X, Y, X + realW, Y + realH)

                mcplatform.win32gui.SetWindowPlacement(hwndOwner, (0, showCmd, ptMin, ptMax, rect))

            config.settings.setWindowPlacement.set(True)
            config.save()
        elif self.win:
            maximized = config.settings.windowMaximized.get()
            if DEBUG_WM:
                print "maximized", maximized
            if maximized:
                geom = self.win.get_root_rect()
                in_w, in_h = self.win.get_size()
                x, y = int((geom[2] - in_w) / 2), int((geom[3] - in_h) / 2)
                os.environ['SDL_VIDEO_CENTERED'] = '1'
            else:
                os.environ['SDL_VIDEO_CENTERED'] = '0'
                x, y = config.settings.windowX.get(), config.settings.windowY.get()
                wwh = self.win.get_size()
            if DEBUG_WM:
                print "x", x, "y", y
                print "wwh 2", wwh

        if splash:
            # Setup the OGL display
            GL.glLoadIdentity()
            GLU.gluOrtho2D(0, wwh[0], 0, wwh[1])
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_ACCUM_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT)

            swh = splash.get_size()
            _x, _y = (wwh[0] / 2 - swh[0] / 2, wwh[1] / 2 - swh[1] / 2)
            w, h = swh

            try:
                data = image.tostring(splash, 'RGBA_PREMULT', 1)
            except ValueError:
                data = image.tostring(splash, 'RGBA', 1)
            except ValueError:
                data = image.tostring(splash, 'RGB', 1)

            # Set the raster position
            GL.glRasterPos(_x, _y)

            GL.glDrawPixels(w, h,
                            GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, numpy.fromstring(data, dtype='uint8'))

        if splash:
            display.flip()

        if self.win:
            if not maximized:
                wwh = self.getWindowSize()
            if DEBUG_WM:
                print "wwh 3", wwh
            self.win.set_position((x, y), update=True)
            if DEBUG_WM:
                print "* self.win.get_position()", self.win.get_position()

        try:
            iconpath = os.path.join(directories.getDataDir(), 'favicon.png')
            iconfile = file(iconpath, 'rb')
            icon = pygame.image.load(iconfile, 'favicon.png')
            display.set_icon(icon)
        except Exception as e:
            logging.warning('Unable to set icon: {0!r}'.format(e))

        # Let initialize OpenGL stuff after the splash.
#         GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
#         GL.glAlphaFunc(GL.GL_NOTEQUAL, 0)
#         GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
 
        # textures are 256x256, so with this we can specify pixel coordinates
        GL.glMatrixMode(GL.GL_TEXTURE)
        GL.glScale(1 / 256., 1 / 256., 1 / 256.)

        self.display = d

        self.loadTextures()