Jump to content
  • Advertisement
Sign in to follow this  
DavidOng

OpenGL rendering to VB.net / 2010 picture box

This topic is 2550 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
I can show you how to render to a panel which is pretty much the same thing. This is using the Tao framework.

Private Function InitWindow() As Boolean
Dim pixelFormat As Integer

Dim pfd As New Gdi.PIXELFORMATDESCRIPTOR()
' pfd Tells Windows How We Want Things To Be
pfd.nSize = CShort(Marshal.SizeOf(pfd))
' Size Of This Pixel Format Descriptor
pfd.nVersion = 1
' Version Number
' Format Must Support Window
' Format Must Support OpenGL
pfd.dwFlags = Gdi.PFD_DRAW_TO_WINDOW Or Gdi.PFD_SUPPORT_OPENGL Or Gdi.PFD_DOUBLEBUFFER
' Format Must Support Double Buffering
pfd.iPixelType = CByte(Gdi.PFD_TYPE_RGBA)
' Request An RGBA Format
pfd.cColorBits = CByte(32)
' Select Our Color Depth
pfd.cRedBits = 0
' Color Bits Ignored
pfd.cRedShift = 0
pfd.cGreenBits = 0
pfd.cGreenShift = 0
pfd.cBlueBits = 0
pfd.cBlueShift = 0
pfd.cAlphaBits = 0
' No Alpha Buffer
pfd.cAlphaShift = 0
' Shift Bit Ignored
pfd.cAccumBits = 0
' No Accumulation Buffer
pfd.cAccumRedBits = 0
' Accumulation Bits Ignored
pfd.cAccumGreenBits = 0
pfd.cAccumBlueBits = 0
pfd.cAccumAlphaBits = 0
pfd.cDepthBits = 16
' 16Bit Z-Buffer (Depth Buffer)
pfd.cStencilBits = 0
' No Stencil Buffer
pfd.cAuxBuffers = 0
' No Auxiliary Buffer
pfd.iLayerType = CByte(Gdi.PFD_MAIN_PLANE)
' Main Drawing Layer
pfd.bReserved = 0
' Reserved
pfd.dwLayerMask = 0
' Layer Masks Ignored
pfd.dwVisibleMask = 0
pfd.dwDamageMask = 0

m_hDC = User.GetDC(panel1.Handle)
' Attempt To Get A Device Context
If m_hDC = IntPtr.Zero Then
ShutdownWindow()
MessageBox.Show("Can't Create A GL Device Context.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.[Error])
Return False
End If

pixelFormat = Gdi.ChoosePixelFormat(m_hDC, pfd)

If pixelFormat = 0 Then
ShutdownWindow()
MessageBox.Show("Can't Find A Suitable PixelFormat.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.[Error])
Return False
End If

If Not Gdi.SetPixelFormat(m_hDC, pixelFormat, pfd) Then
ShutdownWindow()
MessageBox.Show("Can't Set The PixelFormat.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.[Error])
Return False
End If

m_hRC = Wgl.wglCreateContext(m_hDC)

If m_hRC = IntPtr.Zero Then
ShutdownWindow()
MessageBox.Show("Can't Create A GL Rendering Context.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.[Error])
Return False
End If

If Not Wgl.wglMakeCurrent(m_hDC, m_hRC) Then
ShutdownWindow()
MessageBox.Show("Can't Activate The GL Rendering Context.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.[Error])
Return False
End If

ReSizeGLScene(panel1.Width, panel1.Height)

If Not InitGL() Then
ShutdownWindow()
MessageBox.Show("Initialization Failed.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.[Error])
Return False
End If

Return True
End Function

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!