Announcement

Collapse
No announcement yet.

In OpenGL, can we use XPRINT to print out its graphics to a printer?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • In OpenGL, can we use XPRINT to print out its graphics to a printer?

    How do we use XPRINT in OpenGL programs ? I would like to print out OpenGL graphics to
    an ordinary printer.

  • #2
    Originally posted by Anne Wilson View Post
    How do we use XPRINT in OpenGL programs ? I would like to print out OpenGL graphics to
    an ordinary printer.
    How is the graphic displayed?
    If you are drawing to a PB graphic window or control, you can just copy it to the XPrint.
    If not, you will have to use the DC and bitblt() to copy the data over to the XPrint.
    If it is on your screen, you should be able to use XPRINT with it.
    The world is strange and wonderful.*
    I reserve the right to be horrifically wrong.
    Please maintain a safe following distance.
    *wonderful sold separately.

    Comment


    • #3
      It is on the screen, the following is the code

      Code:
      ' Draw circle.bas
      ' http://www.garybeene.com/power/code/gbsnippets_gbs_00603.htm
      '  Thanks to Gary
      
       ' draws a circle using   %gl_line_loop series of lines
       ' there is no circle command in OpenGL
      
      #COMPILE EXE
      #DIM ALL
      #INCLUDE "win32api.inc"
      #INCLUDE "gl.inc"
      #INCLUDE "glu.inc"
      
      GLOBAL hDlg, hDC, hRC AS DWORD
      GLOBAL H(), anglex, angley, anglez, scalefactor AS SINGLE
      
      FUNCTION PBMAIN() AS LONG
        DIALOG NEW PIXELS, 0, "OpenGL Circle",,, 320, 240,%WS_OVERLAPPEDWINDOW TO hDlg
        DIALOG SHOW MODAL hdlg CALL dlgproc
      END FUNCTION
      
      CALLBACK FUNCTION dlgproc()
         LOCAL pt AS POINT
         LOCAL XDelta, YDelta AS SINGLE
         STATIC SpinInWork,XLast,YLast AS LONG
      
         SELECT CASE CB.MSG
            CASE %WM_INITDIALOG : GetRenderContext
                                  InitializeScene
                                  ScaleFactor = 1
            CASE %WM_PAINT      : DrawScene 0,0,0  'redraw with no rotation
            CASE %WM_SIZE       : ResizeScene LO(WORD, CB.LPARAM), HI(WORD, CB.LPARAM)
                                  DrawScene 0,0,0  'redraw with no rotation
            CASE %WM_CLOSE      : wglmakecurrent %null, %null 'unselect rendering context
                                  wgldeletecontext hRC        'delete the rendering context
                                  releasedc hDlg, hDC         'release device context
            CASE %WM_MOUSEWHEEL
               SELECT CASE HI(INTEGER,CB.WPARAM)
                  CASE > 0  : ScaleFactor = ScaleFactor + 0.1 : DrawScene 0,0,0
                  CASE < 0  : ScaleFactor = ScaleFactor - 0.1 : DrawScene 0,0,0
               END SELECT
            CASE %WM_SetCursor
               SELECT CASE HI(WORD, CB.LPARAM)
                  CASE %WM_LBUTTONDOWN
                     SpinInWork = 1
                     GetCursorPos pt              'pt has xy screen coordinates
                     ScreenToClient hDlg, pt       'pt now has dialog client coordinates
                     XLast = Pt.x
                     YLast = Pt.y
                  CASE %WM_MOUSEMOVE
                     IF SpinInWork THEN
                        GetCursorPos pt           'pt has xy screen coordinates
                        ScreenToClient hDlg, pt    'pt now has dialog client coordinates
                        IF pt.y < 0 THEN EXIT SELECT
                        XDelta = XLast - Pt.x
                        YDelta = YLast - Pt.y
                        DrawScene -YDelta, -XDelta, 0
                        XLast = pt.x
                        YLast = pt.y
                     END IF
                  CASE %WM_LBUTTONUP
                     SpinInWork = 0
               END SELECT
         END SELECT
      END FUNCTION
      
      SUB GetRenderContext
         LOCAL pfd AS PIXELFORMATDESCRIPTOR   'pixel format properties for device context
         pfd.nSize       =  SIZEOF(PIXELFORMATDESCRIPTOR)
         pfd.nVersion    =  1
         pfd.dwFlags     = %pfd_draw_to_window OR %pfd_support_opengl OR %pfd_doublebuffer
         pfd.dwlayermask = %pfd_main_plane
         pfd.iPixelType  = %pfd_type_rgba
         pfd.ccolorbits  = 24
         pfd.cdepthbits  = 24
      
         hDC = GetDC(hDlg)                                      'DC for dialog
         SetPixelFormat(hDC, ChoosePixelFormat(hDC, pfd), pfd)  'set properties of device context
         hRC = wglCreateContext (hDC)                           'get rendering context
         wglMakeCurrent hDC, hRC                                'make the RC current
      END SUB
      
      SUB InitializeScene
        ' glClearColor 0,0,0,0     'sets color to be used with glClear
         glClearColor 245,255,250,1
         glClearDepth 1           'sets zvalue to be used with glClear
      
         glDepthFunc %gl_less                                'specify how depth-buffer comparisons are made
         glEnable %gl_depth_test                             'enable depth testing
         glShadeModel %gl_smooth                             'smooth shading
         glHint %gl_perspective_correction_hint, %gl_nicest  'best quality rendering
      
      END SUB
      
      SUB ResizeScene (w AS LONG, h AS LONG)
         glViewport 0, 0, w, h             'resize viewport to match window size
         glMatrixMode %gl_projection       'select the projection matrix
         glLoadIdentity                    'reset the projection matrix
         gluPerspective 45, w/h, 0.1, 100  'calculate the aspect ratio of the Window
         glMatrixMode %gl_modelview        'select the modelview matrix
      END SUB
      
      SUB DrawScene (dx AS SINGLE, dy AS SINGLE, dz AS SINGLE)
         STATIC anglex, angley, anglez AS SINGLE
      
         glClear %gl_color_buffer_bit OR %gl_depth_buffer_bit  'clear buffers
         glLoadIdentity               'clear the modelview matrix
      
         glTranslatef 0,0,-75
         glScalef scalefactor, scalefactor, scalefactor
         glRotatef -20, 1,0,0
      
         anglex = anglex + dx : glRotatef anglex, 1,0,0
         angley = angley + dy : glRotatef angley, 0,1,0
         anglez = anglez + dz : glRotatef anglez, 0,0,1
      
         DrawCircle
      
         SwapBuffers hDC              'display the buffer (image)
      END SUB
      
      '====================================
      SUB DrawCircle
         LOCAL angle  AS DOUBLE
         LOCAL i AS LONG
         glLineWidth 0.5
         glEnable( %GL_LINE_SMOOTH )
         glEnable( %GL_POLYGON_SMOOTH )
         glHint( %GL_LINE_SMOOTH_HINT, %GL_NICEST )
         glHint( %GL_POLYGON_SMOOTH_HINT, %GL_NICEST )
      
       ' to make the circle smoother use more steps in the loop
         glBegin %gl_line_loop
         FOR i = 0 TO 10000
             ' color them blue
               glcolor3ub 0,0,255
      
            angle = 2 * 3.14 * i / 10000
            glVertex3f COS(angle)*5, SIN(angle)*5, 0
         NEXT i
         glEnd
      END SUB

      Comment


      • #4
        Thanks Kurtz, what codes should I use to enable XPRINT ing from the code in #3?

        Comment


        • #5
          Originally posted by Anne Wilson View Post
          Thanks Kurtz, what codes should I use to enable XPRINT ing from the code in #3?
          I don't seem to have Jose's includes, so I cannot run the code.
          However, you can see that you are using the DC already for drawing to the dialog.
          Just use that DC to copy the image to a bitmap or the xprint image using bitblt().
          You will need to get the DC for the bitmap or the XPRINT virtual page, using
          the XPRINT GET DC statement or the GRAPHIC GET DC statement.
          The world is strange and wonderful.*
          I reserve the right to be horrifically wrong.
          Please maintain a safe following distance.
          *wonderful sold separately.

          Comment

          Working...
          X