0

我正在尝试使用 NASMX 在 NASM 中使用 OpenGL 编写一个简单的程序。我在 C 中有此代码的工作版本,它可以工作。汇编版本并没有真正起作用。它编译并运行,但它只显示黑屏而不是带有白色像素的黑屏:)ChangeDisplaySettingsA似乎没有改变显示设置。

我宁愿不使用 NASMX,但我缺乏关于如何在没有 NASMX 的情况下执行此操作的知识。

我想我使用参数的方式有问题。所以你怎么看?这段代码有什么问题?一个工作代码示例的链接会很棒!

%include 'nasmx-1.0\inc\nasmx.inc'
%include 'nasmx-1.0\inc\win32\windows.inc'
%include 'nasmx-1.0\inc\win32\kernel32.inc'
%include 'nasmx-1.0\inc\win32\user32.inc'
%include 'nasmx-1.0\inc\win32\gdi32.inc'
%include 'nasmx-1.0\inc\win32\opengl32.inc'
%include 'nasmx-1.0\inc\win32\msvcrt.inc'

entry entrypoint

XRES    equ     1024
YRES    equ     786

[section .text]
proc    entrypoint, ptrdiff_t argcount, ptrdiff_t cmdline
locals none
    invoke  ChangeDisplaySettingsA, ptrdiff_t [dmScreenSettings], 0x00000004
    invoke  CreateWindowExA, 0, szEdit, 0, WS_POPUP + WS_VISIBLE, 0, 0, XRES, YRES, 0, 0, 0, 0
    invoke  GetDC, eax
    mov     ptrdiff_t [hDc], eax
    invoke  ChoosePixelFormat, ptrdiff_t [hDc], pfd
    invoke  SetPixelFormat, ptrdiff_t [hDc], eax, pfd
    invoke  wglCreateContext, ptrdiff_t [hDc]
    invoke  wglMakeCurrent, ptrdiff_t [hDc], eax
    invoke  ShowCursor, FALSE
    invoke  glViewport, 0, 0, XRES, YRES
    invoke  glMatrixMode, 0x1701
    invoke  glLoadIdentity
    invoke  glOrtho, 0, XRES, 0, YRES, -1, 1
    invoke  glMatrixMode, 0x1700
    invoke  glLoadIdentity
.intro_loop:
    invoke  glColor3ub, 255, 255, 255
    invoke  glBegin, 0x0000
    invoke  glVertex2i, 100, 100
    invoke  glEnd
    invoke  SwapBuffers, ptrdiff_t [hDc]
    invoke  PeekMessageA, 0, 0, 0, 0, PM_REMOVE
    invoke  GetAsyncKeyState, VK_ESCAPE
    cmp     eax, dword 0
    je      .intro_loop
    invoke  ExitProcess, 0
endproc

[section .bss]
    hDc:            reserve(ptrdiff_t) 1

[section .data]
    szEdit:         declare(NASMX_TCHAR) NASMX_TEXT("edit"), 0x0
    NASMX_ISTRUC pfd, PIXELFORMATDESCRIPTOR
        NASMX_AT nSize, 0
        NASMX_AT nVersion, 1
        NASMX_AT dwFlags, 33
        NASMX_AT iPixelType, 32
        NASMX_AT cColorBits, 0
        NASMX_AT cRedBits, 0
        NASMX_AT cRedShift, 0
        NASMX_AT cGreenBits, 0
        NASMX_AT cGreenShift, 0
        NASMX_AT cBlueBits, 0
        NASMX_AT cBlueShift, 0
        NASMX_AT cAlphaBits, 0
        NASMX_AT cAlphaShift, 0
        NASMX_AT cAccumBits, 0
        NASMX_AT cAccumRedBits, 0
        NASMX_AT cAccumGreenBits, 0
        NASMX_AT cAccumBlueBits, 0
        NASMX_AT cAccumAlphaBits, 32
        NASMX_AT cDepthBits, 0
        NASMX_AT cStencilBits, 0
        NASMX_AT cAuxBuffers, 0
        NASMX_AT iLayerType, 0
        NASMX_AT bReserved, 0
        NASMX_AT dwLayerMask, 0
        NASMX_AT dwVisibleMask, 0
        NASMX_AT dwDamageMask, 0
    NASMX_IENDSTRUC
    NASMX_ISTRUC dmScreenSettings, DEVMODE
        NASMX_AT dmDeviceName, ""
        NASMX_AT dmSpecVersion, 0
        NASMX_AT dmDriverVersion, 0
        NASMX_AT dmSize, 156
        NASMX_AT dmDriverExtra, 0
        NASMX_AT dmFields, 1572864
        NASMX_AT dmOrientation, 0
        NASMX_AT dmPaperSize, 0
        NASMX_AT dmPaperiLength, 0
        NASMX_AT dmPaperWidth, 0
        NASMX_AT dmScale, 0
        NASMX_AT dmCopies, 0
        NASMX_AT dmDefaultSource, 0
        NASMX_AT dmPrintQuality, 0
        NASMX_AT dmColor, 0
        NASMX_AT dmDuplex, 0
        NASMX_AT dmYResolution, 0
        NASMX_AT dmTTOption, 0
        NASMX_AT dmCollate, 0
        NASMX_AT dmFormName, ""
        NASMX_AT dmUnusedPadding, 0
        NASMX_AT dmBitsPerPel, 0
        NASMX_AT dmPelsWidth, XRES
        NASMX_AT dmPelsHeight, YRES
        NASMX_AT dmDisplayFlags, 0
        NASMX_AT dmDisplayFrequency, 0
        NASMX_AT dmICMMethod, 0
        NASMX_AT dmICMIntent, 0
        NASMX_AT dmMediaType, 0
        NASMX_AT dmDitherType, 0
        NASMX_AT dmReserved1, 0
        NASMX_AT dmReserved2, 0
        NASMX_AT dmPanningWidth, 0
        NASMX_AT dmPanningHeight, 0
    NASMX_IENDSTRUC
4

2 回答 2

2

你确定你在推动正确的论点吗?请记住,像这样的函数glOrtho需要双精度数,而不是浮点数。

于 2012-09-03T18:46:58.897 回答
0

请检查

用于 NASMX 的 WIN32 的 OpenGL 演示

NASMX v1.2 具有此 OpenGL 演示以及 GL 和 GLUT 包括。

NASMX 下载 - Sourceforge.net

于 2013-01-31T12:15:49.197 回答