Announcement

Collapse
No announcement yet.

How to annotate OPenGL objects with labels ?

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

  • How to annotate OPenGL objects with labels ?

    I have the following 3D OpenGL object which requires annotation of its nodes.

    How do I do this labeling ?

    Click image for larger version

Name:	annotate.png
Views:	1
Size:	2.8 KB
ID:	774260

  • #2

    The following is part of my program to produce the above object
    The object is constructed via a series of nodes or points with x,y,z coordinates

    And I would need these nodes to be labelled as A, B, C, D, ...........

    Code:
           glLineWidth 5
              ' Lines
                glBegin %gl_lines
    
               ' color it blue
                glcolor3ub 0,0,255
    
    
             '  draw the frame members
                FOR I =  1 TO NM
                   J1  =  mbJ1(I)
                   J2  =  mbJ2(I)
    
                   X1  =  ndXCoord(J1)
                   Y1  =  ndYCoord(J1)
                   Z1  =  ndZCoord(J1)
    
                   X2  =  ndXCoord(J2)
                   Y2  =  ndYCoord(J2)
                   Z2  =  ndZCoord(J2)
    
                   glvertex3f  X1 ,Y1 ,Z1
                   glvertex3f  X2 ,Y2 ,Z2
                NEXT I
    
             glEnd


    Also, how to print this drawing to the printer ?

    Comment


    • #3
      I have found a text displaying method from Jose's site http://www.jose.it-berater.org/smffo...1&topic=2346.0

      Code:
       ' =====================================================================================
         METHOD glPrint (BYVAL x AS LONG, BYVAL y AS LONG, BYREF szText AS ASCIIZ, BYVAL nSet AS LONG, BYVAL FontBase AS DWORD, BYREF TextureHandle AS DWORD)
      
            IF nSet > 1 THEN nSet = 1
      
            glBindTexture %GL_TEXTURE_2D, TextureHandle ' Select our font texture
            glDisable %GL_DEPTH_TEST                    ' Disables depth testing
            glMatrixMode %GL_PROJECTION                 ' Select the projection matrix
            glPushMatrix                                ' Store the projection matrix
            glLoadIdentity                              ' Reset the projection matrix
            glOrtho 0, 640, 0, 480, -1, 1               ' Set up an ortho screen
            glMatrixMode %GL_MODELVIEW                  ' Select the modelview matrix
            glPushMatrix                                ' Store the modelview matrix
            glLoadIdentity                              ' Reset the modelview matrix
            glTranslated x, y, 0                        ' Position the text (0,0 - bottom left)
            glListBase FontBase - 32 + (128 * nSet)     ' Choose the font set (0 or 1)
            glCallLists LEN(szText), %GL_UNSIGNED_BYTE, szText  ' Write the text to the screen
            glMatrixMode %GL_PROJECTION                 ' Select the projection matrix
            glPopMatrix                                 ' Restore the old projection matrix
            glMatrixMode %GL_MODELVIEW                  ' Select the modelview matrix
            glPopMatrix                                 ' Restore the old projection matrix
            glEnable %GL_DEPTH_TEST                     ' Enables depth testing
      
         END METHOD
      but upon inserting this code into the program in #2 , no text can be display!!



      Comment


      • #4
        Any experts on OpenGL who help me with this text thing? It looks like OpenGL does not support text ?

        Comment


        • #5
          Anne, Patrice Terrier contributed something on GL fonts long ago, have a look in the Source Code section.

          Comment


          • #6
            until finding a way to use text for labels to vertices, i suggest a practical approach in the OpenGL desert; use textured rectangles as labels.
            i have used example from Jose's site: http://www.jose.it-berater.org/smffo...1&topic=2357.0 as a template for testing the following experiment. all the virtue is for Jose who's his examples enable the people to test opengl and other tools.
            my experiments located in SUB SetupScene for textures preparation, and in SUB DrawScene
            as i am too beginner in powerbasic and in opengl alike, certainly there are several inappropriate codes, so correct it as necessary and as you want .
            i have used a triangle and then attach A to the right vertex and B to the left vertex C to the top
            the output is rotating and the labels (appears) as attached to the vertices.
            https://www.opengl.org/discussion_bo...onnect-objects


            extract the attached pictures to the same folder as the code
            they are A256.bmp, B256.bmp, C256.bmp, Green256.bmp, football.png
            if you have used football.png instead of A256.bmp then you get a transparent football label at the right edge of the triangle

            Code:
            ' SED_PBWIN - Use the PBWIN compiler
            #COMPILE EXE
            #DIM ALL
            
            #INCLUDE "glu.inc"
            #INCLUDE "GDIPLUS.INC"
            #INCLUDE "GDIPUTILS.INC"
            
            $WindowCaption = "NeHe Lesson 06"
            
            %GL_WINDOWWIDTH  = 640         ' Window width
            %GL_WINDOWHEIGHT = 480         ' Window height
            %GL_BITSPERPEL   = 16          ' Color resolution in bits per pixel
            %GL_DEPTHBITS    = 16          ' Depth of the depth (z-axis) buffer
            
            GLOBAL hDC AS LONG             ' Device context handle
            'global TextureHandle(5) AS DWORD
            'DIM TextureHandle(5) as SHARED DWORD
            GLOBAL TextureHandle() AS DWORD 'redimmed again below as REDIM TextureHandle(1 TO 5)
            
            GLOBAL xrot AS SINGLE
            GLOBAL yrot AS SINGLE
            GLOBAL zrot AS SINGLE
            
            ' =======================================================================================
            ' All the setup goes here
            ' =======================================================================================
            SUB SetupScene (BYVAL hwnd AS DWORD, BYVAL nWidth AS LONG, BYVAL nHeight AS LONG)
            
               LOCAL hr, i AS LONG
               'LOCAL strTextureData AS STRING
               DIM strTextureData(1 TO 5) AS STRING
               LOCAL TextureWidth, TextureHeight AS LONG
            
               ' Specify clear values for the color buffers
               glClearColor 0.0!, 0.0!, 0.0!, 0.0!
               ' Specify the clear value for the depth buffer
               glClearDepth 1.0!
               ' Specify the value used for depth-buffer comparisons
               glDepthFunc %GL_LESS
               ' Enable depth comparisons and update the depth buffer
               glEnable %GL_DEPTH_TEST
               ' Select smooth shading
               glShadeModel %GL_SMOOTH
            
               'glDisable %GL_LIGHTING
               'glEnable %GL_LIGHTING
               glLineWidth 3
               glPolygonMode( %GL_FRONT_AND_BACK, %GL_LINE )
               DIM a(1 TO 5) AS STRING
               a(1) = "A256.bmp"   'using a(1) to represent the picture does not work
               a(2) = "B256.bmp"   'using a(2) to represent the picture does not work
               a(3) = "C256.bmp"
               a(4) = "Green256.bmp"
               REDIM TextureHandle(1 TO 5)
               ' Load bitmap texture from disk
               FOR i=1 TO 4
            
               IF i = 1 THEN
                   hr = GdiPlusLoadTexture("A256.bmp", TextureWidth, TextureHeight, strTextureData(i), %TRUE)
                  ELSEIF i = 2 THEN
                   hr = GdiPlusLoadTexture("B256.bmp", TextureWidth, TextureHeight, strTextureData(i), %TRUE)
                  ELSEIF i = 3 THEN
                   hr = GdiPlusLoadTexture("C256.bmp", TextureWidth, TextureHeight, strTextureData(i), %TRUE)
                  ELSE
                  hr = GdiPlusLoadTexture("Green256.bmp", TextureWidth, TextureHeight, strTextureData(i), %TRUE)
               END IF
               ' Assign an OpenGL handle to this texture
               glGenTextures i, TextureHandle(i)
            
               ' Activate our newly created texture
               glEnable %GL_TEXTURE_2D
               glTexEnvf %GL_TEXTURE_ENV, %GL_TEXTURE_ENV_MODE, %GL_MODULATE
               glBindTexture %GL_TEXTURE_2D, TextureHandle(i)
            
               ' Create the texture
               glTexParameteri %GL_TEXTURE_2D, %GL_TEXTURE_MAG_FILTER, %GL_LINEAR
               glTexParameteri %GL_TEXTURE_2D, %GL_TEXTURE_MIN_FILTER, %GL_LINEAR
            
               glTexImage2D %GL_TEXTURE_2D, 0, %GL_RGBA, TextureWidth, TextureHeight, 0, _
                            %GL_RGBA, %GL_UNSIGNED_BYTE, BYVAL STRPTR(strTextureData(i))
               NEXT
            
            
            END SUB
            ' =======================================================================================
            
            ' =======================================================================================
            ' Resize the scene
            ' =======================================================================================
            SUB ResizeScene (BYVAL hwnd AS DWORD, BYVAL nWidth AS LONG, BYVAL nHeight AS LONG)
            
               ' Prevent divide by zero making height equal one
               IF nHeight = 0 THEN nHeight = 1
               ' Reset the current viewport
               glViewport 0, 0, nWidth, nHeight
               ' Select the projection matrix
               glMatrixMode %GL_PROJECTION
               ' Reset the projection matrix
               glLoadIdentity
               ' Calculate the aspect ratio of the window
               gluPerspective 45.0!, nWidth / nHeight, 0.1!, 100.0!
               ' Select the model view matrix
               glMatrixMode %GL_MODELVIEW
               ' Reset the model view matrix
               glLoadIdentity
            
            END SUB
            ' =======================================================================================
            
            ' =======================================================================================
            ' Draw the scene
            ' =======================================================================================
            SUB DrawScene (BYVAL hwnd AS DWORD, BYVAL nWidth AS LONG, BYVAL nHeight AS LONG)
              'glColor4f 1.0,1.0,1.0,  1.0 'Full Brightness. 50% Alpha ( NEW )
              'glBlendFunc %GL_SRC_ALPHA,%GL_ONE 'Blending Function For Translucency Based On Source Alpha Value ( NEW )
            
              glClearColor 0.5, 0.5, 0.5, 1.0
               ' Clear the screen buffer
               glClear %GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT
               ' Reset the view
               glLoadIdentity
            
               glPushMatrix
               glTranslatef 0.0!, 0.0!, -5.0!       ' Move left 1.5 units and into the screen 6.0
               glRotatef xrot, 1.0!, 0.0!, 0.0!           ' Rotate on the x axis
               glRotatef yrot, 0.0!, 1.0!, 0.0!           ' Rotate on the y axis
               glRotatef zrot, 0.0!, 0.0!, 1.0!           ' Rotate on the z axis
               glBindTexture %GL_TEXTURE_2D, TextureHandle(4)
               glPolygonMode( %GL_FRONT_AND_BACK, %GL_LINE )
            
            
               glBegin %GL_TRIANGLES                 ' Drawing using triangles
                  'glColor3f   1.0!, 1.0!, 0.0!       ' Set the color to red
                  glTexCoord2f 0.0!, 0.0!
                  glVertex3f  0.0!, 1.0!, 0.0!       ' Top
                  'glColor3f   0.0!, 1.0!, 0.0!       ' Set the color to green
                  glTexCoord2f 1.0!, 0.0
                  glVertex3f  1.0!,-1.0!, 0.0!       ' Bottom right
                  'glColor3f   0.0!, 0.0!, 1.0!       ' Set the color to blue
                  glTexCoord2f 1.0!, 1.0
                  glVertex3f -1.0!,-1.0!, 0.0!       ' Bottom left
               glEnd
            
               'xrot = xrot + 1.0!                         ' x axis rotation
               yrot = yrot + 1.0!                         ' y axis rotation
               'zrot = zrot + 0.4!                         ' z axis rotation
            
               glPushMatrix
               glTranslatef 1.0!, -1.0!, 0.02!
            
            
               glBindTexture %GL_TEXTURE_2D, TextureHandle(1)
            
               glPolygonMode( %GL_FRONT_AND_BACK, %GL_FILL )
               glBegin %GL_QUADS
                  glTexCoord2f 0.0!, 0.0! : glVertex3f -0.3!, -0.3!,  0.0!      ' bottom left of the texture and quad
                  glTexCoord2f 1.0!, 0.0! : glVertex3f  0.3!, -0.3!,  0.0!      ' bottom right of the texture and quad
                  glTexCoord2f 1.0!, 1.0! : glVertex3f  0.3!,  0.3!,  0.0!      ' top right of the texture and quad
                  glTexCoord2f 0.0!, 1.0! : glVertex3f -0.3!,  0.3!,  0.0!      ' top left of the texture and quad
            
               glEnd
            
               glBindTexture %GL_TEXTURE_2D, TextureHandle(2)
               'note glTranslatef is relative to the pevious glTranslatef movement
               glTranslatef -2.0!, 0.0!, 0.0!
               glBegin %GL_QUADS
                  glTexCoord2f 0.0!, 0.0! : glVertex3f -0.3!, -0.3!,  0.0!      ' bottom left of the texture and quad
                  glTexCoord2f 1.0!, 0.0! : glVertex3f  0.3!, -0.3!,  0.0!      ' bottom right of the texture and quad
                  glTexCoord2f 1.0!, 1.0! : glVertex3f  0.3!,  0.3!,  0.0!      ' top right of the texture and quad
                  glTexCoord2f 0.0!, 1.0! : glVertex3f -0.3!,  0.3!,  0.0!      ' top left of the texture and quad
            
               glEnd
            
               glBindTexture %GL_TEXTURE_2D, TextureHandle(3)
               'note glTranslatef is relative to the pevious glTranslatef movement
               glTranslatef 1.0!, 2.0!, 0.0!
               glBegin %GL_QUADS
                  glTexCoord2f 0.0!, 0.0! : glVertex3f -0.3!, -0.3!,  0.0!      ' bottom left of the texture and quad
                  glTexCoord2f 1.0!, 0.0! : glVertex3f  0.3!, -0.3!,  0.0!      ' bottom right of the texture and quad
                  glTexCoord2f 1.0!, 1.0! : glVertex3f  0.3!,  0.3!,  0.0!      ' top right of the texture and quad
                  glTexCoord2f 0.0!, 1.0! : glVertex3f -0.3!,  0.3!,  0.0!      ' top left of the texture and quad
            
               glEnd
            
            
               glPopMatrix
               glPopMatrix
            
            
            END SUB
            ' =======================================================================================
            
            ' =======================================================================================
            ' Cleanup
            ' =======================================================================================
            SUB Cleanup (BYVAL hwnd AS DWORD)
               DIM i AS LONG
               FOR i=1 TO 4
               ' Delete the texture
               IF TextureHandle(i) THEN glDeleteTextures(i, TextureHandle(i))
               NEXT
            END SUB
            ' =======================================================================================
            
            ' =======================================================================================
            ' Processes keystrokes
            ' Parameters:
            ' * hwnd = Window hande
            ' * vKeyCode = Virtual key code
            ' * bKeyDown = %TRUE if key is pressed; %FALSE if it is released
            ' =======================================================================================
            SUB ProcessKeystrokes (BYVAL hwnd AS DWORD, BYVAL vKeyCode AS LONG, BYVAL bKeyDown AS LONG)
            
               SELECT CASE AS LONG vKeyCode
            
                  CASE %VK_ESCAPE
                     ' Quit if Esc key pressed
                     SendMessage hwnd, %WM_CLOSE, 0, 0
            
               END SELECT
            
            END SUB
            ' =======================================================================================
            
            ' =======================================================================================
            ' Main
            ' =======================================================================================
            FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
            
               LOCAL  hwnd        AS DWORD
               LOCAL  wcex        AS WNDCLASSEX
               LOCAL  szClassName AS ASCIIZ * 256
               LOCAL  szCaption   AS ASCIIZ * 256
               LOCAL  msg         AS tagMSG
               LOCAL  rc          AS RECT
               LOCAL  bDone       AS LONG
               LOCAL  nLeft       AS LONG
               LOCAL  nTop        AS LONG
               LOCAL  nWidth      AS LONG
               LOCAL  nHeight     AS LONG
               LOCAL  dwStyle     AS DWORD
               LOCAL  dwStyleEx   AS DWORD
               STATIC vKeyCode    AS LONG
               STATIC bKeyDown    AS LONG
               LOCAL  t           AS DOUBLE
               LOCAL  t0          AS DOUBLE
               LOCAL  fps         AS DOUBLE
               LOCAL  nFrames     AS LONG
               LOCAL  dm          AS DEVMODE
               LOCAL  bFullScreen AS LONG
               LOCAL  lResult     AS LONG
            
               ' Register the window class
               szClassName        = "PBOPENGL"
               wcex.cbSize        = SIZEOF(wcex)
               wcex.style         = %CS_HREDRAW OR %CS_VREDRAW OR %CS_OWNDC
               wcex.lpfnWndProc   = CODEPTR(WndProc)
               wcex.cbClsExtra    = 0
               wcex.cbWndExtra    = 0
               wcex.hInstance     = hInstance
               wcex.hCursor       = LoadCursor (%NULL, BYVAL %IDC_ARROW)
               wcex.hbrBackground = %NULL
               wcex.lpszMenuName  = %NULL
               wcex.lpszClassName = VARPTR(szClassName)
               wcex.hIcon         = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Sample, if resource icon: LoadIcon(hInst, "APPICON")
               wcex.hIconSm       = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Remember to set small icon too..
               RegisterClassEx wcex
            
                ' Ask the user which screen mode he prefers
                lResult = MessageBox(%NULL, "Would you like to run in fullscreen mode?", _
                         "Start fullScreen?", %MB_YESNOCANCEL OR %MB_ICONQUESTION)
               SELECT CASE lResult
                  CASE %IDCANCEL : EXIT FUNCTION
                  CASE %IDYES    : bFullScreen = %TRUE
                  CASE %IDNO     : bFullScreen = %FALSE
               END SELECT
            
               ' Window size
               nWidth  = %GL_WINDOWWIDTH
               nHeight = %GL_WINDOWHEIGHT
            
               IF bFullScreen THEN
                  ' Change display settings
                  dm.dmSize       = SIZEOF(dm)
                  dm.dmPelsWidth  = nWidth
                  dm.dmPelsHeight = nHeight
                  dm.dmBitsPerPel = %GL_BITSPERPEL
                  dm.dmFields     = %DM_BITSPERPEL OR %DM_PELSWIDTH OR %DM_PELSHEIGHT
                  IF ChangeDisplaySettings(dm, %CDS_FULLSCREEN) = 0 THEN ShowCursor %FALSE
               END IF
            
               ' Window caption
               szCaption = $WindowCaption
            
               ' Window styles
               IF ISFALSE bFullScreen THEN
                  dwStyle = %WS_OVERLAPPEDWINDOW
                  dwStyleEx = %WS_EX_APPWINDOW OR %WS_EX_WINDOWEDGE
               ELSE
                  dwStyle = %WS_POPUP
                  dwStyleEx = %WS_EX_APPWINDOW
               END IF
            
               ' Create the window
               hwnd = CreateWindowEx( _
                        dwStyleEx, _                      ' extended styles
                        szClassName, _                    ' window class name
                        szCaption, _                      ' window caption
                        dwStyle, _                        ' window style
                        nLeft, _                          ' initial x position
                        nTop, _                           ' initial y position
                        nWidth, _                         ' initial x size
                        nHeight, _                        ' initial y size
                        %NULL, _                          ' parent window handle
                        0, _                              ' window menu handle
                        hInstance, _                      ' program instance handle
                        BYVAL %NULL)                      ' creation parameters
            
               ' Retrieve the coordinates of the window's client area
               GetClientRect hwnd, rc
               ' Initialize the new OpenGl window
               SetupScene hwnd, rc.nRight - rc.nLeft, rc.nBottom - rc.nTop
            
               ' Show the window
               ShowWindow hwnd, nCmdShow
               UpdateWindow hwnd
            
               DO UNTIL bDone
            
                  ' Windows message pump
                  DO WHILE PeekMessage(msg, %NULL, 0, 0, %PM_REMOVE)
                     IF msg.message = %WM_QUIT THEN
                        bDone = %TRUE
                     ELSE
                        IF msg.message = %WM_KEYDOWN THEN
                           vKeyCode = msg.wParam
                           bKeyDown = %TRUE
                        ELSEIF msg.message = %WM_KEYUP THEN
                           vKeyCode = msg.wParam
                           bKeyDown = %FALSE
                        END IF
                        TranslateMessage msg
                        DispatchMessage msg
                     END IF
                  LOOP
            
                  IF ISFALSE bFullScreen THEN
                     ' Get time and mouse position
                     t = INT(TIMER)
                     ' Calculate and display FPS (frames per second)
                     IF t > t0 OR nFrames = 0 THEN
                        fps = nFrames \ (t - t0)
                        wsprintf szCaption, $WindowCaption & " (%i FPS)", BYVAL fps
                        SetWindowText hwnd, szCaption
                        t0 = t
                        nFrames = 0
                     END IF
                     nFrames = nFrames + 1
                  END IF
            
                  ' Draw the scene
                  DrawScene hwnd, nWidth, nHeight
                  ' Exchange the front and back buffers
                  SwapBuffers hDC
            
                  ' Process the keystrokes
                  IF vKeyCode THEN
                     ProcessKeystrokes hwnd, vKeyCode, bKeyDown
                     vKeyCode = 0
                  END IF
            
               LOOP
            
               ' Retore defaults
               IF bFullScreen THEN
                  ChangeDisplaySettings BYVAL %NULL, 0
                  ShowCursor %TRUE
               END IF
            
               FUNCTION = msg.wParam
            
            END FUNCTION
            ' =======================================================================================
            
            ' =======================================================================================
            ' Main window procedure
            ' =======================================================================================
            FUNCTION WndProc (BYVAL hwnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
            
               LOCAL  pf           AS LONG
               LOCAL  pfd          AS PIXELFORMATDESCRIPTOR
               STATIC hRC          AS LONG
            
               SELECT CASE wMsg
            
                  CASE %WM_SYSCOMMAND
            
                     ' Disable the Windows screensaver
                     IF (wParam AND &HFFF0) = %SC_SCREENSAVE THEN EXIT FUNCTION
            
                     ' Close the window
                     IF (wParam AND &HFFF0) = %SC_CLOSE THEN
                        SendMessage hwnd, %WM_CLOSE, 0, 0
                        EXIT FUNCTION
                     END IF
            
                  CASE %WM_CREATE
            
                     ' Retrieve the device context handle
                     hDC = GetDC(hwnd)
            
                     ' Fill the PIXELFORMATDESCRIPTOR structure
                     pfd.nSize           = SIZEOF(PIXELFORMATDESCRIPTOR)   ' Size of the structure
                     pfd.nVersion        = 1                               ' Version number
                     pfd.dwFlags         = %PFD_DRAW_TO_WINDOW _           ' Format must support window
                                           OR %PFD_SUPPORT_OPENGL _        ' Format must support OpenGL
                                           OR %PFD_DOUBLEBUFFER            ' Format must support double buffering
                     pfd.iPixelType      = %PFD_TYPE_RGBA                  ' Request an RGBA format
                     pfd.cColorBits      = %GL_BITSPERPEL                  ' Number of color bitplanes in each color buffer
                     pfd.cRedBits        = 0                               ' Number of red bitplanes in each RGBA color buffer.
                     pfd.cRedShift       = 0                               ' Shift count for red bitplanes in each RGBA color buffer.
                     pfd.cGreenBits      = 0                               ' Number of green bitplanes in each RGBA color buffer.
                     pfd.cGreenShift     = 0                               ' Shift count for green bitplanes in each RGBA color buffer.
                     pfd.cBlueBits       = 0                               ' Number of blue bitplanes in each RGBA color buffer.
                     pfd.cBlueShift      = 0                               ' Shift count for blue bitplanes in each RGBA color buffer.
                     pfd.cAlphaBits      = 0                               ' Number of alpha bitplanes in each RGBA color buffer
                     pfd.cAlphaShift     = 0                               ' Shift count for alpha bitplanes in each RGBA color buffer.
                     pfd.cAccumBits      = 0                               ' Total number of bitplanes in the accumulation buffer.
                     pfd.cAccumRedBits   = 0                               ' Number of red bitplanes in the accumulation buffer.
                     pfd.cAccumGreenBits = 0                               ' Number of gree bitplanes in the accumulation buffer.
                     pfd.cAccumBlueBits  = 0                               ' Number of blue bitplanes in the accumulation buffer.
                     pfd.cAccumAlphaBits = 0                               ' Number of alpha bitplanes in the accumulation buffer.
                     pfd.cDepthBits      = %GL_DEPTHBITS                   ' Depth of the depth (z-axis) buffer.
                     pfd.cStencilBits    = 0                               ' Depth of the stencil buffer.
                     pfd.cAuxBuffers     = 0                               ' Number of auxiliary buffers.
                     pfd.iLayerType      = %PFD_MAIN_PLANE                 ' Ignored. Earlier implementations of OpenGL used this member, but it is no longer used.
                     pfd.bReserved       = 0                               ' Number of overlay and underlay planes.
                     pfd.dwLayerMask     = 0                               ' Ignored. Earlier implementations of OpenGL used this member, but it is no longer used.
                     pfd.dwVisibleMask   = 0                               ' Transparent color or index of an underlay plane.
                     pfd.dwDamageMask    = 0                               ' Ignored. Earlier implementations of OpenGL used this member, but it is no longer used.
            
                     ' Find a matching pixel format
                     pf = ChoosePixelFormat(hDC, pfd)
                     IF ISFALSE pf THEN
                        MessageBox hwnd, "Can't find a suitable pixel format", _
                                   "Error", %MB_OK OR %MB_ICONEXCLAMATION
                        SendMessage hwnd, %WM_CLOSE, 0, 0
                        EXIT FUNCTION
                     END IF
            
                     ' Set the pixel format
                     IF ISFALSE SetPixelFormat(hDC, pf, pfd) THEN
                        MessageBox hwnd, "Can't set the pixel format", _
                                   "Error", %MB_OK OR %MB_ICONEXCLAMATION
                        SendMessage hwnd, %WM_CLOSE, 0, 0
                        EXIT FUNCTION
                     END IF
            
                     ' Create a new OpenGL rendering context
                     hRC = wglCreateContext(hDC)
                     IF ISFALSE hRC THEN
                        MessageBox hwnd, "Can't create an OpenGL rendering context", _
                                   "Error", %MB_OK OR %MB_ICONEXCLAMATION
                        SendMessage hwnd, %WM_CLOSE, 0, 0
                        EXIT FUNCTION
                     END IF
            
                     ' Make it current
                     IF ISFALSE wglMakeCurrent(hDC,hRC) THEN
                        MessageBox hwnd, "Can't activate the OpenGL rendering context", _
                                   "Error", %MB_OK OR %MB_ICONEXCLAMATION
                        SendMessage hwnd, %WM_CLOSE, 0, 0
                        EXIT FUNCTION
                     END IF
            
                     EXIT FUNCTION
            
                  CASE %WM_DESTROY
                     ' Clear resources
                     Cleanup hwnd
                     ' Release the device and rendering contexts
                     wglMakeCurrent hDC, 0
                     ' Make the rendering context no longer current
                     wglDeleteContext hRC
                     ' Release the device context
                     ReleaseDC hwnd, hDC
                     ' Post an WM_QUIT message
                     PostQuitMessage 0
                     EXIT FUNCTION
            
                  CASE %WM_SIZE
                     ResizeScene hwnd, LO(WORD, lParam), HI(WORD, lParam)
                     EXIT FUNCTION
            
               END SELECT
            
               ' Call the default window procedure to process unhandled messages
               FUNCTION = DefWindowProc(hwnd, wMsg, wParam, lParam)
            
            END FUNCTION
            ' =======================================================================================
            how to print it ? if you mean how to print it in 3d printer then use this utility (GLXtractor):
            https://web.archive.org/web/20151126...lo.at/~alexan/
            it will capture the opengl content from any program as OBJ which then can be used in 3D printer.
            How to use GLXtractor:
            1- compile the code to test.exe
            2- run the GLXtractor program and accept the defaults. click on "Choose App" and choose the test.exe file you have saved before.
            3- click on Ogle Plugin Tab and choose capture texture ... capture. this is to capture the UV and normals data
            4- click Start Application
            5- when the test.exe run use either the mouse or ALT-TAB to focus on the GLXtractor window , and press ctrl-shift-f . you will notice the rendering stop for a second or more (may be 10 seconds for very big meshes.)
            6- exit the test.exe
            7- look at My Documents - Xtracted folder (or whatever you choose before running test exe)
            you will find test.obj and a texture


            Attached Files

            Comment


            • #7
              Search for "Scaffolding" and/or for advanced OpenGL billboarding text display "3D chart".
              Note: GDImage is able to use any TTF font to render into OpenGL.
              Patrice Terrier
              www.zapsolution.com
              www.objreader.com
              Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

              Comment


              • #8
                Thanks so much George, it is a doable with bmp images. I'm interested in printing to only ordinary printer, but the 3D printer
                would be a very good idea for future work especially when you need to print a building's CAD drawings in 3D.


                Brilliant Patrice, that's an academy award for your work of art 3D chart. It has no equals!

                Comment


                • #9
                  i forgot to add transparency functions to display transparent textures
                  add these at the beginning of SUB DrawScene:
                  glEnable %GL_BLEND
                  glBlendFunc %GL_SRC_ALPHA, %GL_ONE_MINUS_SRC_ALPHA


                  with some transparent pics it will look like this:
                  Click image for larger version  Name:	annotate.PNG Views:	1 Size:	10.8 KB ID:	774290

                  wherever we want to disable transparency add this glDisable %GL_BLEND before the drawing of specific rectangle
                  glEnable %GL_BLEND will enable it again
                  regarding the glTranslatef , every usage of it is relative to the previous glTranslatef, but using absolute coordinates is more convenient, so adding glPushMatrix glPopMatrix will solve this, here is the modified SUB DrawScene to display transparent pictures and to use absolute Translate
                  note that i have used a green texture for the triangle because using glColor3f will affect the rectangles texture color (another problem needs solving)
                  replace SUB DrawScene in my previous post with this:
                  Edit: i position the first glTranslatef for the triangle at 0,0,0
                  and have used a camera gluLookAt 0,0,5, 0,0,0, 0,1,0
                  Code:
                  ' =======================================================================================
                  ' Draw the scene
                  ' =======================================================================================
                  SUB DrawScene (BYVAL hwnd AS DWORD, BYVAL nWidth AS LONG, BYVAL nHeight AS LONG)
                    glEnable %GL_BLEND
                    glBlendFunc %GL_SRC_ALPHA, %GL_ONE_MINUS_SRC_ALPHA
                    glClearColor 0.5, 0.5, 0.5, 1.0
                     ' Clear the screen buffer
                     glClear %GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT
                     ' Reset the view
                     glLoadIdentity
                  
                     gluLookAt 0,0,5, 0,0,0, 0,1,0 ' position a camera at 0,0,5 and look at 0,0,0
                     glPushMatrix
                     glTranslatef 0.0!, 0.0!, 0.0!       ' center the triangle at 0,0,0
                     glRotatef xrot, 1.0!, 0.0!, 0.0!           ' Rotate on the x axis
                     glRotatef yrot, 0.0!, 1.0!, 0.0!           ' Rotate on the y axis
                     glRotatef zrot, 0.0!, 0.0!, 1.0!           ' Rotate on the z axis
                     glBindTexture %GL_TEXTURE_2D, TextureHandle(4)
                     glPolygonMode( %GL_FRONT_AND_BACK, %GL_LINE )
                  
                  
                     glBegin %GL_TRIANGLES                 ' Drawing using triangles
                        'glColor3f   1.0!, 1.0!, 0.0!       ' Set the color to red
                        glTexCoord2f 0.0!, 0.0!
                        glVertex3f  0.0!, 1.0!, 0.0!       ' Top
                        'glColor3f   0.0!, 1.0!, 0.0!       ' Set the color to green
                        glTexCoord2f 1.0!, 0.0
                        glVertex3f  1.0!,-1.0!, 0.0!       ' Bottom right
                        'glColor3f   0.0!, 0.0!, 1.0!       ' Set the color to blue
                        glTexCoord2f 1.0!, 1.0
                        glVertex3f -1.0!,-1.0!, 0.0!       ' Bottom left
                     glEnd
                  
                     'xrot = xrot + 1.0!                         ' x axis rotation
                     yrot = yrot + 1.0!                         ' y axis rotation
                     'zrot = zrot + 0.4!                         ' z axis rotation
                  
                     glPushMatrix
                     glPushMatrix 'for absolute glTranslatef
                     glTranslatef 1.0!, -1.0!, 0.02!
                     glBindTexture %GL_TEXTURE_2D, TextureHandle(1)
                  
                     glPolygonMode( %GL_FRONT_AND_BACK, %GL_FILL )
                     glBegin %GL_QUADS
                        glTexCoord2f 0.0!, 0.0! : glVertex3f -0.3!, -0.3!,  0.0!      ' bottom left of the texture and quad
                        glTexCoord2f 1.0!, 0.0! : glVertex3f  0.3!, -0.3!,  0.0!      ' bottom right of the texture and quad
                        glTexCoord2f 1.0!, 1.0! : glVertex3f  0.3!,  0.3!,  0.0!      ' top right of the texture and quad
                        glTexCoord2f 0.0!, 1.0! : glVertex3f -0.3!,  0.3!,  0.0!      ' top left of the texture and quad
                  
                     glEnd
                     glPopMatrix 'for absolute glTranslatef
                     'glDisable %GL_BLEND
                     glBindTexture %GL_TEXTURE_2D, TextureHandle(2)
                  
                     'glTranslatef -2.0!, 0.0!, 0.0!
                     glPushMatrix 'for absolute glTranslatef
                     glTranslatef -1.0!, -1.0!, 0.02!
                     glBegin %GL_QUADS
                        glTexCoord2f 0.0!, 0.0! : glVertex3f -0.3!, -0.3!,  0.0!      ' bottom left of the texture and quad
                        glTexCoord2f 1.0!, 0.0! : glVertex3f  0.3!, -0.3!,  0.0!      ' bottom right of the texture and quad
                        glTexCoord2f 1.0!, 1.0! : glVertex3f  0.3!,  0.3!,  0.0!      ' top right of the texture and quad
                        glTexCoord2f 0.0!, 1.0! : glVertex3f -0.3!,  0.3!,  0.0!      ' top left of the texture and quad
                  
                     glEnd
                     glPopMatrix 'for absolute glTranslatef
                     glBindTexture %GL_TEXTURE_2D, TextureHandle(3)
                  
                     glPushMatrix 'for absolute glTranslatef
                     glTranslatef 0.0!, 1.0!, 0.02!
                     glBegin %GL_QUADS
                        glTexCoord2f 0.0!, 0.0! : glVertex3f -0.3!, -0.3!,  0.0!      ' bottom left of the texture and quad
                        glTexCoord2f 1.0!, 0.0! : glVertex3f  0.3!, -0.3!,  0.0!      ' bottom right of the texture and quad
                        glTexCoord2f 1.0!, 1.0! : glVertex3f  0.3!,  0.3!,  0.0!      ' top right of the texture and quad
                        glTexCoord2f 0.0!, 1.0! : glVertex3f -0.3!,  0.3!,  0.0!      ' top left of the texture and quad
                  
                     glEnd
                     glPopMatrix 'for absolute glTranslatef
                  
                     glPopMatrix
                     glPopMatrix
                  
                  
                  END SUB
                  ' =======================================================================================

                  Comment


                  • #10
                    Hi Anne,

                    I use GLPrint to annotate my OpenGL graphic windows (www.gpr-survey.com). You need to build the font using


                    code:

                    '******************************************************************************
                    SUB BuildFont()
                    '******************************************************************************
                    DIM hFont AS LONG
                    FontBase = glGenLists(256) ' Storage For 256 Characters
                    hFont = CreateFont( -.5, _ ' Height Of Font
                    0, _ ' Width Of Font
                    0, _ ' Angle Of Escapement
                    0, _ ' Orientation Angle
                    %FW_normal, _ ' Font Weight
                    0, _ ' Italic
                    0, _ ' Underline
                    0, _ ' Strikeout
                    %ANSI_CHARSET, _ ' Character Set Identifier
                    %OUT_tt_only_PRECIS, _ ' Output Precision
                    %CLIP_DEFAULT_PRECIS, _ ' Clipping Precision
                    %antialiased_QUALITY, _ ' Output Quality
                    %FF_Decorative, _ ' Family And Pitch
                    "VictorianD") ' Font Name
                    ' %OUT_TT_ONLY_PRECIS, _ ' Output Precision
                    ' %antialiased_QUALITY, _ ' Output Quality

                    CALL SelectObject(hpicdc, hFont) ' Selects The Font We Created
                    CALL wglUseFontOutlines(hpicdc, _ ' Select The Current DC
                    0, _ ' Starting Character
                    255, _ ' Number Of Display Lists To Build
                    fontbase, _ ' Starting Display Lists
                    0.0, _ ' Deviation From The True Outlines
                    0.0, _ ' Font Thickness In The Z Direction
                    %WGL_FONT_polygons, _ ' Use Polygons, Not Lines
                    BYVAL VARPTR(gmf(0))) ' Address Of Buffer To Recieve Data
                    DeleteObject (SelectObject(hpicdc, hFont))
                    END SUB

                    code end:


                    Comment


                    • #11
                      Thanks so much Dean and George

                      I have got it right now

                      Click image for larger version

Name:	sFRAME1.png
Views:	1
Size:	12.3 KB
ID:	774301


                      Click image for larger version

Name:	sf2.png
Views:	1
Size:	13.2 KB
ID:	774300

                      Comment


                      • #12
                        Click image for larger version

Name:	sf3.png
Views:	1
Size:	12.5 KB
ID:	774303

                        Comment

                        Working...
                        X