News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

OpenGL clears Window to black

Started by TheSpider, December 15, 2018, 10:16:58 AM

Previous topic - Next topic

TheSpider

Hi Guys,

I wanted to start drawing with OpenGL and tried to set up a basic call to clear the Window to some color.
Unfortunately for some reason my Window stays black although I should be clearing it to a pink color.  :(

Here is how I'm initializing OpenGL although I do not think this is the issue

Win32InitializeOpenGl proc Window:HWND

local WindowDC:HDC
local OpenGLRC:HGLRC
local DesiredPixelFormat:PIXELFORMATDESCRIPTOR
local SuggestedPixelFormatIndex:dword
local SuggestedPixelFormat:PIXELFORMATDESCRIPTOR

invoke GetDC, Window
mov WindowDC, rax

InitStructToZero DesiredPixelFormat
mov DesiredPixelFormat.nSize, sizeof DesiredPixelFormat
mov DesiredPixelFormat.nVersion, 1
mov DesiredPixelFormat.dwFlags, PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or PFD_DOUBLEBUFFER
mov DesiredPixelFormat.cColorBits, 24
mov DesiredPixelFormat.cAlphaBits, 8
mov DesiredPixelFormat.iLayerType, PFD_MAIN_PLANE

invoke ChoosePixelFormat, WindowDC, addr DesiredPixelFormat
mov SuggestedPixelFormatIndex, eax

invoke DescribePixelFormat, WindowDC, SuggestedPixelFormatIndex, \
sizeof SuggestedPixelFormat,\
addr SuggestedPixelFormat
invoke SetPixelFormat, WindowDC, SuggestedPixelFormatIndex, \
   addr SuggestedPixelFormat

invoke wglCreateContext, WindowDC
mov OpenGLRC, rax

invoke wglMakeCurrent, WindowDC, OpenGLRC
Assert rax

invoke ReleaseDC, Window, WindowDC
ret

Win32InitializeOpenGl endp


And then each time in the main loop this is how I update my Window.
Win32UdpateWindow proc DeviceContext:HDC

invoke glViewport, 0, 0, GlobalWindowHeight, GlobalWindowWidth
invoke glClearColor, FLT4(1.0), FLT4(0.0), FLT4(1.0), FLT4(0.0)
invoke glClear, GL_COLOR_BUFFER_BIT

invoke SwapBuffers, DeviceContext
ret

Win32UdpateWindow endp


I had to define a few symbols on my own because a few I could not find in the masm32 include64 directory.
I hope that is not the issue.

Anyone know what might be the problem ?

Cheers

Siekmanski

Think SwapBuffers is not doing it's job.
You are missing some valuable include files.

Here are some excellent Masm (32 bit) OpenGl examples by hitchhikr.
Including all OpenGl include files you need.

http://perso.orange.fr/franck.charlet/Ogl_Asm.zip
Creative coders use backward thinking techniques as a strategy.

TheSpider

Thank you

So that means I should work in 32-bit not 64-bit ?

Siekmanski

That's up to you, those examples are 32-bit only.
You can translate them yourself to 64-bit if you really need to.
Creative coders use backward thinking techniques as a strategy.

TheSpider

Thank you.
What exactly would I have to do to translate them to 64-bit ?
I'm not sure about the process.

jj2007

Quote from: TheSpider on January 05, 2019, 08:02:51 PM
What exactly would I have to do to translate them to 64-bit ?

You would have to replace the type of those elements that depend on the bitness of your code (pointers and handles) with something like SIZE_P, where
IF @AssembleAs64
  SIZE_P equ QWORD
else
  SIZE_P equ DWORD
endif