Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

OpenGL sdk Objects example

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

  • PBWin OpenGL sdk Objects example

    dear powerbasic friends, I have finished and modified an old powerbasic openGL example with sdk window frame. I have included in zip folder all "include" files, exe and *.bas file you need for compiling. have fun with it and don't hesitate to change the objects and colours

    Code:
    #COMPILE EXE
    #DIM ALL
    #REGISTER DEFAULT
    
    GLOBAL szAppName AS ASCIIZ * 64
    GLOBAL hMainDC   AS LONG
    GLOBAL PI        AS DOUBLE
    
    #INCLUDE "win32api.inc"
    #INCLUDE "gl.inc"
    #INCLUDE "glu.inc"
    #INCLUDE "glfunc.inc"
    
    
    FUNCTION ResizeViewport(BYVAL lWidth AS LONG, BYVAL lHeight AS LONG) AS LONG
      LOCAL dAspect AS DOUBLE
    
      glViewport 10, 10, lWidth, lHeight
      dAspect = lWidth / lHeight
    
      glMatrixMode %GL_PROJECTION
      glLoadIdentity
    
    '  gluPerspective 90 / dAspect, dAspect, 0.1, 360
       gluPerspective 140 / dAspect, dAspect, 0.5, 360
       
      glMatrixMode %GL_MODELVIEW
    END FUNCTION
    
    
    SUB RenderWorld(BYVAL v AS SINGLE, BYVAL dif AS SINGLE)
      STATIC i AS SINGLE
      STATIC m AS SINGLE
    
      glClear %GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT
    
      glMatrixMode %GL_MODELVIEW
      glLoadIdentity
    
      glPushMatrix
        glTranslatef -2, 0, -4
        glRotatef v, 1.0, 0.0, 1.0
        glRotatef -v, 0.0, 1.0, 0.0
        glBegin %GL_POLYGON
        FOR i = 0 TO 359 STEP 4
          m = m + dif/100000
          glColor3f SIN(i/180*PI-m*2), SIN(i/180*PI-m), SIN(i/180*PI+m)
          glVertex3f SIN(i/180*PI)*2, COS(i/180*PI)^3, SIN(i/180*PI-m)^4
        NEXT i
        glEnd
      glPopMatrix
    
      glPushMatrix
        glTranslatef 0, -2.5, -4
        glRotatef v, 1.0, 0.0, 1.0
        glRotatef -v, 0.0, 1.0, 0.0
        glBegin %GL_POLYGON
        FOR i = 0 TO 359 STEP 4
          m = m + dif/100000
          glColor3f SIN(i/180*PI-m*2), SIN(2*i/180*PI-m), SIN(i/180*PI+m)
          glVertex3f SIN(i/180*PI)*1.5, -COS(i/180*PI)^3, SIN(i/180*PI-m)^3
        NEXT i
        glEnd
      glPopMatrix
    
      glPushMatrix
        glTranslatef 0, 2.5, -4
        glRotatef v, 1.0, 0.0, 1.0
        glRotatef -v, 0.0, 1.0, 0.0
        glBegin %GL_POLYGON
        FOR i = 0 TO 359 STEP 4
          m = m + dif/100000
          glColor3f SIN(i/180*PI-m*2), COS(2*i/180*PI-m), SIN(i/180*PI+m)
          glVertex3f SIN(i/180*PI)*2.5, COS(i/180*PI)^3, SIN(i/180*PI-m)^3
        NEXT i
        glEnd
      glPopMatrix
    
      glPushMatrix
        glTranslatef 3, 0, -4
        glRotatef v, 2.0, 0.0, 0.0
        glRotatef -v, 0.0, 2.0, 1.0
        glRotatef v, 0.0, 1.0, 2.0
        glBegin %GL_POLYGON
        FOR i = 0 TO 359 STEP 4
          m = m + dif/200000
          glColor3f SIN(4*i/180*PI-m*2), SIN(2*i/180*PI-m), SIN(2*i/180*PI+m+2000)
          glVertex3f SIN(i/180*PI)*2, -COS(i/180*PI)^3, SIN(i/180*PI-m)^3
        NEXT i
        glEnd
      glPopMatrix
    
    
      glFinish
      SwapBuffers hMainDC
    END SUB
    
    
    FUNCTION WndMainProc(BYVAL hWnd AS LONG, BYVAL uMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
      STATIC lpRect AS RECT
      STATIC hRC AS LONG
    
      SELECT CASE uMsg
      CASE %WM_CREATE
        hMainDC = GetDC(hWnd)
        IF ISFALSE(SetupPixelFormat(hMainDC)) THEN
          MSGBOX "SetupPixelFormat() failed",,szAppName
          PostQuitMessage 0
          EXIT FUNCTION
        END IF
    
        hRC = wglCreateContext(hMainDC)
        IF ISFALSE(hRC) THEN
          MSGBOX "wglCreateContext() failed",,szAppName
          PostQuitMessage 0
          EXIT FUNCTION
        END IF
        wglMakeCurrent hMainDC, hRC
        GetClientRect hWnd, lpRect
        InitGL
        ResizeViewport lpRect.nRight, lpRect.nBottom
        ShowWindow hWnd, %SW_SHOW
    
      CASE %WM_CHAR
        SELECT CASE wParam
        CASE 27
          PostQuitMessage 0
        END SELECT
    
      CASE %WM_SIZE
        GetClientRect hWnd, lpRect
        ResizeViewport lpRect.nRight, lpRect.nBottom
    
      CASE %WM_DESTROY
        wglMakeCurrent %NULL, %NULL
        IF hRC THEN
          wglDeleteContext hRC
        END IF
        IF hMainDC THEN
          ReleaseDC hWnd, hMainDC
          PostQuitMessage 0
        END IF
    
      CASE ELSE
        FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)
      END SELECT
    END FUNCTION
    
    
    FUNCTION WINMAIN(BYVAL hInstance AS LONG, BYVAL hPrevInstance AS LONG, BYVAL lpCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) EXPORT AS LONG
      LOCAL lpWndClass  AS WNDCLASS
      LOCAL dwCurTime   AS DWORD
      LOCAL dwOldTime   AS DWORD
      LOCAL cameraV     AS SINGLE
      LOCAL lpMsg       AS tagMSG
      LOCAL hWnd        AS LONG
    
      szAppName = "Frank's experimental SDK OpenGL 3D Objects (part one)"
    
      PI = ATN(1) * 8 '4
    
      lpWndClass.style         = 0
      lpWndClass.lpfnWndProc   = CODEPTR(WndMainProc)
      lpWndClass.cbClsExtra    = 0
      lpWndClass.cbWndExtra    = 0
      lpWndClass.hInstance     = hInstance
      lpWndClass.hIcon         = %NULL
      lpWndClass.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
      lpWndClass.hbrBackground = GetStockObject(%BLACK_BRUSH)
      lpWndClass.lpszMenuName  = %NULL
      lpWndClass.lpszClassName = VARPTR(szAppName)
    
      IF ISFALSE(RegisterClass(lpWndClass)) THEN
        MSGBOX "RegisterClass() failed",,szAppName
        EXIT FUNCTION
      END IF
    
      hWnd = CreateWindowEx(%WS_EX_APPWINDOW, szAppName, szAppName, %WS_BORDER OR %WS_DLGFRAME OR %WS_CLIPSIBLINGS OR %WS_OVERLAPPEDWINDOW, 50, 50, 800, 600, %NULL, %NULL, hInstance, BYVAL %NULL)
    
      IF ISFALSE(hWnd) THEN
        MSGBOX "CreateWindowEx() failed",,szAppName
        UnregisterClass szAppName, hInstance
        EXIT FUNCTION
      END IF
    
      dwCurTime = GetTickCount()
      DO
        DO WHILE PeekMessage(lpMsg, %NULL, 0, 0, %PM_NOREMOVE)
          IF GetMessage(lpMsg, %NULL, 0, 0) THEN
            TranslateMessage lpMsg
            DispatchMessage lpMsg
          ELSE
            EXIT FUNCTION
          END IF
        LOOP
        dwOldTime = dwCurTime
        dwCurTime = GetTickCount()
        cameraV = cameraV + (dwCurTime - dwOldTime) / 250
        RenderWorld cameraV, (dwCurTime - dwOldTime)
      LOOP
    END FUNCTION
    if you have any problems for compiling, please send a message to this board and I will check and try to help.

    thanks, nice day, frank
    Attached Files

  • #2
    correct lights

    => ok, here the right openGL example with correct lights

    Code:
    '---------------> frank's new sdk openGL example with lights and objects 01.juni.2010 ------------
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    #COMPILE EXE
    #DIM ALL
    #REGISTER DEFAULT
    
    GLOBAL szAppName AS ASCIIZ * 76
    GLOBAL hMainDC   AS LONG
    GLOBAL PI        AS DOUBLE
    
    #INCLUDE "win32api.inc"
    #INCLUDE "gl.inc"
    #INCLUDE "glu.inc"
    #INCLUDE "glfunc.inc"
    
    
    FUNCTION ResizeViewport(BYVAL lWidth AS LONG, BYVAL lHeight AS LONG) AS LONG
      LOCAL dAspect AS DOUBLE
      DIM   LightAmbient(3) AS SINGLE
      DIM   LightDiffuse(3) AS SINGLE
      DIM   LightPosition(3) AS SINGLE
      
      ARRAY ASSIGN LightAmbient()  = 0.5, 0.5, 0.5, 1.0
      ARRAY ASSIGN LightDiffuse()  = 1.0, 1.0, 1.0, 1.0
      ARRAY ASSIGN LightPosition() = 20.0, 0.0, 30.0, 1.0
      
      glViewport 10, 10, lWidth, lHeight
      dAspect = lWidth / lHeight
    
      glMatrixMode %GL_PROJECTION
      glLoadIdentity
    
      gluPerspective 140 / dAspect, dAspect, 0.5, 360
    
      glMatrixMode %GL_MODELVIEW
    
       glClearColor 0.0!, 0.0!, 0.0!, 0.0!
       glClearDepth 2.0!
       glDepthFunc %GL_LESS
       glEnable %GL_DEPTH_TEST
       glShadeModel %GL_SMOOTH
    
        CALL glLightfv(%GL_LIGHT0, %GL_AMBIENT, LightAmbient(0))
        CALL glLightfv(%GL_LIGHT0, %GL_DIFFUSE, LightDiffuse(0))
        CALL glLightfv(%GL_LIGHT0, %GL_POSITION, LightPosition(0))
        CALL glEnable(%GL_LIGHT0)
        CALL glEnable(%GL_LIGHTING)
        CALL glEnable(%GL_COLOR_MATERIAL)
       
    END FUNCTION
    
    
    SUB RenderWorld(BYVAL v AS SINGLE, BYVAL dif AS SINGLE)
      STATIC i AS SINGLE
      STATIC m AS SINGLE
    
      glClear %GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT
    
      glMatrixMode %GL_MODELVIEW
      glLoadIdentity
    
      glPushMatrix
        glTranslatef -2, 0, -4
        glRotatef v, 1.0, 0.0, 1.0
        glRotatef -v, 0.0, 1.0, 0.0
        glBegin %GL_POLYGON
        FOR i = 0 TO 359 STEP 4
          m = m + dif/100000
          glColor3f SIN(i/180*PI-m*2), SIN(i/180*PI-m), SIN(i/180*PI+m)
          glVertex3f SIN(i/180*PI)*2, COS(i/180*PI)^3, SIN(i/180*PI-m)^4
        NEXT i
        glEnd
      glPopMatrix
    
      glPushMatrix
        glTranslatef 0, -2.5, -4
        glRotatef v, 1.0, 0.0, 1.0
        glRotatef -v, 0.0, 1.0, 0.0
        glBegin %GL_POLYGON
        FOR i = 0 TO 359 STEP 4
          m = m + dif/100000
          glColor3f SIN(i/180*PI-m*2), SIN(2*i/180*PI-m), SIN(i/180*PI+m)
          glVertex3f SIN(i/180*PI)*1.5, -COS(i/180*PI)^3, SIN(i/180*PI-m)^3
        NEXT i
        glEnd
      glPopMatrix
    
      glPushMatrix
        glTranslatef 0, 2.5, -4
        glRotatef v, 1.0, 0.0, 1.0
        glRotatef -v, 0.0, 1.0, 0.0
        glBegin %GL_POLYGON
        FOR i = 0 TO 359 STEP 4
          m = m + dif/100000
          glColor3f SIN(i/180*PI-m*2), COS(2*i/180*PI-m), SIN(i/180*PI+m)
          glVertex3f SIN(i/180*PI)*2.5, COS(i/180*PI)^3, SIN(i/180*PI-m)^3
        NEXT i
        glEnd
      glPopMatrix
    
      glPushMatrix
        glTranslatef 3, 0, -4
        glRotatef v, 2.0, 0.0, 0.0
        glRotatef -v, 0.0, 2.0, 1.0
        glRotatef v, 0.0, 1.0, 2.0
        glBegin %GL_POLYGON
        FOR i = 0 TO 359 STEP 4
          m = m + dif/200000
          glColor3f SIN(4*i/180*PI-m*2), SIN(2*i/180*PI-m), SIN(2*i/180*PI+m+2000)
          glVertex3f SIN(i/180*PI)*2, -COS(i/180*PI)^3, SIN(i/180*PI-m)^3
        NEXT i
        glEnd
      glPopMatrix
      glFinish
      
      SwapBuffers hMainDC
    END SUB
    
    
    FUNCTION WndMainProc(BYVAL hWnd AS LONG, BYVAL uMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
      STATIC lpRect AS RECT
      STATIC hRC AS LONG
    
      SELECT CASE uMsg
      CASE %WM_CREATE
        hMainDC = GetDC(hWnd)
        IF ISFALSE(SetupPixelFormat(hMainDC)) THEN
          MSGBOX "SetupPixelFormat() failed",,szAppName
          PostQuitMessage 0
          EXIT FUNCTION
        END IF
    
        hRC = wglCreateContext(hMainDC)
        IF ISFALSE(hRC) THEN
          MSGBOX "wglCreateContext() failed",,szAppName
          PostQuitMessage 0
          EXIT FUNCTION
        END IF
        wglMakeCurrent hMainDC, hRC
        GetClientRect hWnd, lpRect
        InitGL
        ResizeViewport lpRect.nRight, lpRect.nBottom
        ShowWindow hWnd, %SW_SHOW
    
      CASE %WM_CHAR
        SELECT CASE wParam
        CASE 27
          PostQuitMessage 0
        END SELECT
    
      CASE %WM_SIZE
        GetClientRect hWnd, lpRect
        ResizeViewport lpRect.nRight, lpRect.nBottom
    
      CASE %WM_DESTROY
        wglMakeCurrent %NULL, %NULL
        IF hRC THEN
          wglDeleteContext hRC
        END IF
        IF hMainDC THEN
          ReleaseDC hWnd, hMainDC
          PostQuitMessage 0
        END IF
    
      CASE ELSE
        FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)
      END SELECT
    END FUNCTION
    
    
    FUNCTION WINMAIN(BYVAL hInstance AS LONG, BYVAL hPrevInstance AS LONG, BYVAL lpCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) EXPORT AS LONG
      LOCAL lpWndClass  AS WNDCLASS
      LOCAL dwCurTime   AS DWORD
      LOCAL dwOldTime   AS DWORD
      LOCAL cameraV     AS SINGLE
      LOCAL lpMsg       AS tagMSG
      LOCAL hWnd        AS LONG
    
      szAppName = "Frank's experimental SDK OpenGL 3D Objects *lighted ok!* (part one)"
    
      PI = ATN(1) * 8 '4
    
      lpWndClass.style         = 0
      lpWndClass.lpfnWndProc   = CODEPTR(WndMainProc)
      lpWndClass.cbClsExtra    = 0
      lpWndClass.cbWndExtra    = 0
      lpWndClass.hInstance     = hInstance
      lpWndClass.hIcon         = %NULL
      lpWndClass.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
      lpWndClass.hbrBackground = GetStockObject(%BLACK_BRUSH)
      lpWndClass.lpszMenuName  = %NULL
      lpWndClass.lpszClassName = VARPTR(szAppName)
    
      IF ISFALSE(RegisterClass(lpWndClass)) THEN
        MSGBOX "RegisterClass() failed",,szAppName
        EXIT FUNCTION
      END IF
    
      hWnd = CreateWindowEx(%WS_EX_APPWINDOW, szAppName, szAppName, %WS_BORDER OR %WS_DLGFRAME OR %WS_CLIPSIBLINGS OR %WS_OVERLAPPEDWINDOW, 50, 50, 800, 600, %NULL, %NULL, hInstance, BYVAL %NULL)
    
      IF ISFALSE(hWnd) THEN
        MSGBOX "CreateWindowEx() failed",,szAppName
        UnregisterClass szAppName, hInstance
        EXIT FUNCTION
      END IF
    
      dwCurTime = GetTickCount()
      DO
        DO WHILE PeekMessage(lpMsg, %NULL, 0, 0, %PM_NOREMOVE)
          IF GetMessage(lpMsg, %NULL, 0, 0) THEN
            TranslateMessage lpMsg
            DispatchMessage lpMsg
          ELSE
            EXIT FUNCTION
          END IF
        LOOP
        dwOldTime = dwCurTime
        dwCurTime = GetTickCount()
        cameraV = cameraV + (dwCurTime - dwOldTime) / 250
        RenderWorld cameraV, (dwCurTime - dwOldTime)
      LOOP
    END FUNCTION
    a) all again in zip folder! b) the include files you find in my first example!

    best regards, I am glad, I found the treasure with light setup
    bye, good night, frank
    Attached Files
    Last edited by frank bruebach; 1 Jun 2010, 06:18 PM.

    Comment


    • #3
      "blending"

      here it comes:
      new sdk openGL example with "blending" effects , works fine here.

      Code:
      #COMPILE EXE
      #DIM ALL
      #REGISTER DEFAULT
      
      GLOBAL szAppName AS ASCIIZ * 76
      GLOBAL hMainDC   AS LONG
      GLOBAL PI        AS DOUBLE
      
      $INCLUDE "win32api.inc"
      $INCLUDE "gl.inc"
      $INCLUDE "glu.inc"
      $INCLUDE "glfunc.inc"
      
      MACRO GL_SRC_ALPHA                   = &h0302&
      MACRO GL_BLEND                       = &h0BE2&
      MACRO GL_LINEAR                      = &h2601&
      MACRO GL_ONE                         = &h0001&
      MACRO GL_SMOOTH                      = &h1D01&
      MACRO GL_DEPTH_TEST                  = &h0B71&
      
      FUNCTION ResizeViewport(BYVAL lWidth AS LONG, BYVAL lHeight AS LONG) AS LONG
        LOCAL dAspect AS DOUBLE
        DIM   LightAmbient(3) AS SINGLE
        DIM   LightDiffuse(3) AS SINGLE
        DIM   LightPosition(3) AS SINGLE
      
        glViewport 10, 10, lWidth, lHeight
        dAspect = lWidth / lHeight
      
        glMatrixMode %GL_PROJECTION
        glLoadIdentity
      
        gluPerspective 140 / dAspect, dAspect, 0.1, 360 '90
        glMatrixMode %GL_MODELVIEW
      
              glClearColor 0.0, 0.0, 0.0, 0.0
              glShadeModel GL_SMOOTH
              glClearDepth 1.0
              glDisable GL_DEPTH_TEST
              glBlendFunc GL_SRC_ALPHA, GL_ONE
              glEnable GL_BLEND
      
         ARRAY ASSIGN LightAmbient()  = 0.5!, 0.5!, 0.5!, 1.0!
         ARRAY ASSIGN LightDiffuse()  = 1.0!, 1.0!, 1.0!, 1.0!
         ARRAY ASSIGN LightPosition() = 1.0!, 0.0!, 3.0!, -2.0!
      
         glLightfv %GL_LIGHT1, %GL_AMBIENT, LightAmbient(0)
         glLightfv %GL_LIGHT1, %GL_DIFFUSE, LightDiffuse(0)
         glLightfv %GL_LIGHT1, %GL_POSITION, LightPosition(0)
         glEnable %GL_LIGHT1
      
      END FUNCTION
      
      
      SUB RenderWorld(BYVAL v AS SINGLE, BYVAL dif AS SINGLE)
        STATIC i AS SINGLE
        STATIC m AS SINGLE
      
        glClear %GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT
      
        glMatrixMode %GL_MODELVIEW
        glLoadIdentity
      
        glPushMatrix
          glTranslatef -2, 0, -4
          glRotatef v, 1.0, 0.0, 1.0
          glRotatef -v, 0.0, 1.0, 0.0
          glBegin %GL_POLYGON
          FOR i = 0 TO 359 STEP 4
            m = m + dif/100000
            glColor3f SIN(i/180*PI-m*2), SIN(i/180*PI-m), SIN(i/180*PI+m)
            glVertex3f SIN(i/180*PI)*2, COS(i/180*PI)^3, SIN(i/180*PI-m)^4
          NEXT i
          glEnd
        glPopMatrix
      
        glPushMatrix
          glTranslatef 0, -2.5, -4
          glRotatef v, 1.0, 0.0, 1.0
          glRotatef -v, 0.0, 1.0, 0.0
          glBegin %GL_POLYGON
          FOR i = 0 TO 359 STEP 4
            m = m + dif/100000
            glColor3f SIN(i/180*PI-m*2), SIN(2*i/180*PI-m), SIN(i/180*PI+m)
            glVertex3f SIN(i/180*PI)*1.5, -COS(i/180*PI)^3, SIN(i/180*PI-m)^3
          NEXT i
          glEnd
        glPopMatrix
      
        glPushMatrix
          glTranslatef 0, 2.5, -4
          glRotatef v, 1.0, 0.0, 1.0
          glRotatef -v, 0.0, 1.0, 0.0
          glBegin %GL_POLYGON
          FOR i = 0 TO 359 STEP 4
            m = m + dif/100000
            glColor3f SIN(i/180*PI-m*2), COS(2*i/180*PI-m), SIN(i/180*PI+m)
            glVertex3f SIN(i/180*PI)*2.5, COS(i/180*PI)^3, SIN(i/180*PI-m)^3
          NEXT i
          glEnd
        glPopMatrix
      
        glPushMatrix
          glTranslatef 3, 0, -4
          glRotatef v, 2.0, 0.0, 0.0
          glRotatef -v, 0.0, 2.0, 1.0
          glRotatef v, 0.0, 1.0, 2.0
          glBegin %GL_POLYGON
          FOR i = 0 TO 359 STEP 4
            m = m + dif/200000
            glColor3f SIN(4*i/180*PI-m*2), SIN(2*i/180*PI-m), SIN(2*i/180*PI+m+2000)
            glVertex3f SIN(i/180*PI)*2, -COS(i/180*PI)^3, SIN(i/180*PI-m)^3
          NEXT i
          glEnd
        glPopMatrix
        glFinish
      
        SwapBuffers hMainDC
      
      END SUB
      
      
      FUNCTION WndMainProc(BYVAL hWnd AS LONG, BYVAL uMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
        STATIC lpRect AS RECT
        STATIC hRC AS LONG
      
        SELECT CASE uMsg
        CASE %WM_CREATE
          hMainDC = GetDC(hWnd)
          IF ISFALSE(SetupPixelFormat(hMainDC)) THEN
            MSGBOX "SetupPixelFormat() failed",,szAppName
            PostQuitMessage 0
            EXIT FUNCTION
          END IF
      
          hRC = wglCreateContext(hMainDC)
          IF ISFALSE(hRC) THEN
            MSGBOX "wglCreateContext() failed",,szAppName
            PostQuitMessage 0
            EXIT FUNCTION
          END IF
          wglMakeCurrent hMainDC, hRC
          GetClientRect hWnd, lpRect
          InitGL
          ResizeViewport lpRect.nRight, lpRect.nBottom
          ShowWindow hWnd, %SW_SHOW
      
        CASE %WM_CHAR
          SELECT CASE wParam
          CASE 27
            PostQuitMessage 0
          END SELECT
      
        CASE %WM_SIZE
          GetClientRect hWnd, lpRect
          ResizeViewport lpRect.nRight, lpRect.nBottom
      
        CASE %WM_DESTROY
          wglMakeCurrent %NULL, %NULL
          IF hRC THEN
            wglDeleteContext hRC
          END IF
          IF hMainDC THEN
            ReleaseDC hWnd, hMainDC
            PostQuitMessage 0
          END IF
      
        CASE ELSE
          FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)
        END SELECT
      END FUNCTION
      
      
      FUNCTION WINMAIN(BYVAL hInstance AS LONG, BYVAL hPrevInstance AS LONG, BYVAL lpCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) EXPORT AS LONG
        LOCAL lpWndClass  AS WNDCLASS
        LOCAL dwCurTime   AS DWORD
        LOCAL dwOldTime   AS DWORD
        LOCAL cameraV     AS SINGLE
        LOCAL lpMsg       AS tagMSG
        LOCAL hWnd        AS LONG
      
        szAppName = "Frank's experimental SDK OpenGL 3D Objects *blending* (part one)"
      
        PI = ATN(1) * 8 '4
      
        lpWndClass.style         = 0
        lpWndClass.lpfnWndProc   = CODEPTR(WndMainProc)
        lpWndClass.cbClsExtra    = 0
        lpWndClass.cbWndExtra    = 0
        lpWndClass.hInstance     = hInstance
        lpWndClass.hIcon         = %NULL
        lpWndClass.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
        lpWndClass.hbrBackground = GetStockObject(%BLACK_BRUSH)
        lpWndClass.lpszMenuName  = %NULL
        lpWndClass.lpszClassName = VARPTR(szAppName)
      
        IF ISFALSE(RegisterClass(lpWndClass)) THEN
          MSGBOX "RegisterClass() failed",,szAppName
          EXIT FUNCTION
        END IF
      
        hWnd = CreateWindowEx(%WS_EX_APPWINDOW, szAppName, szAppName, %WS_BORDER OR %WS_DLGFRAME OR %WS_CLIPSIBLINGS OR %WS_OVERLAPPEDWINDOW, 50, 50, 800, 600, %NULL, %NULL, hInstance, BYVAL %NULL)
      
        IF ISFALSE(hWnd) THEN
          MSGBOX "CreateWindowEx() failed",,szAppName
          UnregisterClass szAppName, hInstance
          EXIT FUNCTION
        END IF
      
        dwCurTime = GetTickCount()
        DO
          DO WHILE PeekMessage(lpMsg, %NULL, 0, 0, %PM_NOREMOVE)
            IF GetMessage(lpMsg, %NULL, 0, 0) THEN
              TranslateMessage lpMsg
              DispatchMessage lpMsg
            ELSE
              EXIT FUNCTION
            END IF
          LOOP
          dwOldTime = dwCurTime
          dwCurTime = GetTickCount()
          cameraV = cameraV + (dwCurTime - dwOldTime) / 250
          RenderWorld cameraV, (dwCurTime - dwOldTime)
        LOOP
      END FUNCTION
      have done exe and *.bas in zip folder you need.

      new edit: the problem with lights (see my last example) belongs to textured objects like you can see in "nehe" (example 7: http://nehe.gamedev.net/data/lessons....asp?lesson=07) for example. -> I will check if it's necessary to use extra lights for standard scenes like this new example with "blending" effects. now this scene and the objects are brighten and blending up enough in my eyes

      thanks, best regards, frank
      Attached Files
      Last edited by frank bruebach; 1 Jun 2010, 04:19 PM.

      Comment


      • #4
        example with correct "openGL lights" updated, see my second post

        Comment

        Working...
        X