PDA

View Full Version : OpenGL in VBA (Access) Help Please



Bandit73
06-22-2009, 03:33 PM
I am working on an existing program in VBA(Access) which has extensive links to databases, hence i wish to continue using VBA. However I am looking to plot some of the data from the databases in OpenGL.

Does anyone know how to get OpenGL working in VBA(Access)?

I have a newly created window and the handle to it and I have the OpenGL library referenced.
My code seems to run the OpenGL commands but nothing displays.(just a white window)

If it makes any difference I am using access 2007 with VB(A) 6.5

Below is some sample code to draw a triangle which I have been using

Sub Form_Load()
hWndParent = me.hWnd
hWndChild = CreateWindowEx(0, "Test_Class", "", WS_CHILD Or WS_BORDER Or WS_VISIBLE, 200, 200, 200, 200, 0, hWndParent, 0, Application.hWndAccessApp, 0)
EnableOpenGl(hWndChild)
glClearColor 0, 0, 0, 0
Triangle
Do
kresli
DoEvents
loop
End Sub

Sub EnableOpenGL(ghDC As Long)
Dim pfd As PIXELFORMATDESCRIPTOR
ZeroMemory pfd, Len(pfd)
pfd.nSize = Len(pfd)
pfd.nVersion = 1
pfd.dwFlags = PFD_DRAW_TO_WINDOW Or PFD_SUPPORT_OPENGL Or PFD_DOUBLEBUFFER
pfd.iPixelType = PFD_TYPE_RGBA
pfd.cColorBits = 24
pfd.cDepthBits = 32
pfd.iLayerType = PFD_MAIN_PLANE
PixFormat = ChoosePixelFormat(ghDC, pfd)
If PixFormat = 0 Then GoTo ee
SetPixelFormat ghDC, PixFormat, pfd
hRC = wglCreateContext(ghDC)
wglMakeCurrent ghDC, hRC
Exit Sub
ee: MsgBox "Nelze nastavit parametry pro zobrazení grafiky!"
End
End Sub

Sub kresli()
glClear GL_COLOR_BUFFER_BIT
glPushMatrix
glRotatef theta, 0, 0, 1
glCallList triangle_list
glPopMatrix
SwapBuffers getDC(hWndChild)
theta = theta + 1
End Sub

Sub Triangle()
glNewList triangle_list, lstCompile
glBegin GL_TRIANGLES
glColor3f 1, 0, 0: glVertex2f 0, 1
glColor3f 0, 1, 0: glVertex2f 0.87, -0.5
glColor3f 0, 0, 1: glVertex2f -0.87, -0.5
glEnd
glEndList
End Sub

Ilian Dinev
06-22-2009, 06:05 PM
This looks fishy:
SwapBuffers getDC(hWndChild)

Try using the initial ghDC as a param.

See if glGetError reports anything.