Does anyone know how to compile and link a program that uses opengl and glut under nasm? I've tried normal "extern function/import function dll" but it doesn't work. Neither does linking with gl libraries (opengl32.lib glut32.lib glaux.lib glu32.lib apart from glut32.lib which was downloaded from Nate Robins site all were taken from masm package). I use alink. Thanks

ps. Compiling a program without glut also does't work. The includes I have for opengl (nasmgl.inc, nasmglu.inc) require a file called "nwinx.inc", which is currently unreachable (tried google and some nasm related sites). the only example of nasm opengl source comes from a site that's currently closed (http://bizarrecreations.webjump.com). if it helps my code is here: http://deuterol.w.interia.pl/my_gl.asm (haven't had time to fix all the bugs, besides it doesn't even compile..) ,the example: http://deuterol.w.interia.pl/opengl/ntorus.asm and the makefile: http://deuterol.w.interia.pl/opengl/_nasm.bat

I'd appreciate any help becouse it's very important :-)
Posted on 2005-06-22 08:04:11 by deuter
I will refer you to furter help tothe yahoo groups, the includes that you say, about winx... are not available... (I havent finded), tought they are not needed, perhpas  definitions for "data types" or some like that.

By the way, you also can use golink, that dont need library files (.lib), but the path the originall dll...

You only need

I will post some bat files and includes that I use for assemble with alink, golink and perhaps others...

The include files w.inc (a striped version of macros of the normal windows include), general.mac include the macros for do the diferent entry points used by diferent linkers


%include "..\..\include\general.mac"


segment .text class = code use32
%define LINKERUSED GOLINK

extern MessageBoxA
extern __imp_MessageBoxA

MakeEntry

push dword 0 ; OK button
push dword title1
push dword string1
push dword 0
call MessageBoxA

push dword 0 ; OK button
push dword title1
push dword string2
push dword 0
call [__imp_MessageBoxA]

invke MessageBoxA, 0, string3, string3, 0
invkiat MessageBoxA, 0, string4, string4, 0

extern _ExitProcess@4
call _ExitProcess@4

segment .data class=DATA use32

string1: db 'hello world, through redirection',13,10,0
;exported data
title1: db 'Hello',0
string2: db 'hello world, called through import table',13,10,0

string3: db "Hello world, called trough invke (invoke xtern)", 13, 10, 0
string4: db "Hello you, called trought invkiat (invoke iat)", 13, 10, 0


And also is included some macros for "delete" the work for include them like I do in this example (get from another resource.. is an old example); invk, invkiat do the same job, look at them carefully...

Also there is invk taht is used for call functions in the file (because they will not be marked with extern, or inserted __imp_ ...


By the way, the only dismiss aht I have about golink is taht dosent have a command line option for mark segments like shared, that is suported by the assembler... not the linker.

A yes.. I have forgot, for use golink, you should open golinkl.bat and add the dll about OpenGL that are not included.

Hope this help you a little.
Attachments:
Posted on 2005-06-22 10:25:30 by rea
ok I've finally managed to compile the program :-) (just needed to convert opengl32.dll to .lib with a little help from alib and get rid of the include files. they are good for a reference only..) but now I have a new problem becouse my program doesn't display anything but a black screen. I really don't know what can be wrong. it's almost a copy (well in a sense of functionality not the look ;-) of sourcecode from nehe's tutorial#2. if someone has the time to take a look here it is:

global _main

;====================================================================
;? ?KERNEL FUNCTIONS
;====================================================================


;====================================================================
;? ?USER FUNCTIONS
;====================================================================

















;====================================================================
;? ?GDI FUNCTIONS
;====================================================================



;====================================================================
;? ?OPENGL FUNCTIONS
;====================================================================


















;====================================================================
;? ?GLU FUNCTIONS
;====================================================================


section text use32
_main:
;? ?db 0cch
? ? xor eax, eax
? ? push eax
? ? call GetModuleHandleA
? ? mov dword , eax
? ? push dword IDI_APPLICATION?
? ? push dword 0
? ? call LoadIconA
? ? mov , eax
? ? push dword IDC_ARROW
? ? push dword 0
? ? call LoadCursorA
? ? mov , eax
? ? push dword wc
? ? call RegisterClassA
? ? xor eax, eax
? ? push dword eax
? ? push dword
? ? push dword eax
? ? push dword eax
? ? push dword 480
? ? push dword 640
? ? push dword CW_USEDEFAULT
? ? push dword CW_USEDEFAULT
? ? push dword WS_OVERLAPPEDWINDOW | WS_BORDER
? ? push dword WndName
? ? push dword ClassName
? ? push dword 0 ;WS_EX_CLIENTEDGE
? ? call CreateWindowExA
? ? mov dword , eax
? ? push dword SW_SHOW;SW_SHOWMAXIMIZED
? ? push dword
? ? call ShowWindow
? ? push dword
? ? call UpdateWindow
? ? call InitOpenGL? ? ? ? ? ? ? ? ? ? ? ? ? ? ?;<=== GL STUFF
get_msg_loop:
? ? xor eax, eax
? ? push eax
? ? push eax
? ? push dword
? ? call InvalidateRect
? ? xor eax, eax
? ? push eax
? ? push eax
? ? push eax
? ? push dword msg
? ? call GetMessageA
? ? or eax, eax
? ? jz @WM_QUIT
? ? push dword msg
? ? call TranslateMessage
? ? push dword msg
? ? call DispatchMessageA
? ? jmp get_msg_loop
@WM_QUIT:
? ? push eax
? ? call ExitProcess

%define _hwnd ebp+8
%define _umsg ebp+12
%define _wparam ebp+16
%define _lparam ebp+20
WndProc:
? ? push ebp
? ? mov ebp, esp
? ? ? ?
? ? cmp dword [_umsg], WM_DESTROY
? ? jz @WM_DESTROY
? ? cmp dword [_umsg], WM_PAINT
? ? jz @WM_PAINT
? ? cmp dword [_umsg], WM_KEYDOWN
? ? jz @WM_KEYDOWN

? ? push dword [_lparam]
? ? push dword [_wparam]
? ? push dword [_umsg]
? ? push dword [_hwnd]
? ? call DefWindowProcA
? ? pop ebp
? ? ret 16

@WM_DESTROY:
? ? call KillGL
? ? push dword 0
? ? call PostQuitMessage
? ? pop ebp
? ? ret 16

@WM_PAINT:
? ? push dword rect
? ? push dword
? ? call GetClientRect
? ? push dword
? ? pop dword
? ? push dword ps
? ? push dword
? ? call BeginPaint
? ? call GLScene? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ;<=== GL STUFF
? ? push dword ps
? ? push dword
? ? call EndPaint
? ? pop ebp
? ? ret 16

@WM_KEYDOWN:
? ? cmp dword [_wparam], VK_ESCAPE
? ? jz @WM_DESTROY
? ? pop ebp
? ? ret 16

InitOpenGL:
;====================================================================
;? ?GET DC
;====================================================================
? ? push dword
? ? call GetDC
? ? mov dword , eax
;====================================================================
;? ?MATCH DEVICE CONTEXT PIXEL FORMAT TO A GIVEN FORMAT SPECIFICATION
;====================================================================
? ? push dword pfd
? ? push eax
? ? call ChoosePixelFormat
? ? mov dword , eax
;====================================================================
;? ?SET THE GIVEN PIXEL FORMAT
;====================================================================
? ? push dword pfd
? ? push eax
? ? push dword
? ? call SetPixelFormat
;====================================================================
;? ?CREATE RENDERING CONTEXT
;====================================================================
? ? push dword
? ? call wglCreateContext
? ? mov dword , eax
;====================================================================
;? ?MAKE IT CURRENT CONTEXT
;====================================================================
? ? push eax
? ? push dword
? ? call wglMakeCurrent
;====================================================================
;? ?GET CLIENT AREA COORDINATES (0, 0, RIGHT, BOTTOM)
;====================================================================
? ? push dword rect
? ? push dword [_hwnd]
? ? call GetClientRect
;====================================================================
;? ?BEGIN THE GL STUFF
;====================================================================
? ? push dword 000000b71h ; GL_DEPTH_TEST
? ? call glEnable
? ? push dword 000000b44h ; GL_CULL_FACE
? ? call glEnable
? ? push dword 000001d01h ; GL_SMOOTH
? ? call glShadeModel
? ? xor eax, eax
? ? push eax
? ? push eax
? ? push eax
? ? push eax
? ? call glClearColor
? ? push dword 480
? ? push dword 640
? ? push dword 0
? ? push dword 0
? ? call glViewport
? ?
? ? push dword 1701h? ? ? ? ;GL_PROJECTION
? ? call glMatrixMode
? ? call glLoadIdentity

? ?

? ? push dword 1700h? ? ? ? ;GL_MODELVIEW
? ? call glMatrixMode
? ? call glLoadIdentity

? ? ret

KillGL:
? ? xor eax, eax
? ? push eax
? ? push eax
? ? call wglMakeCurrent
? ? push dword
? ? call wglDeleteContext
? ? push dword
? ? push dword
? ? call ReleaseDC
? ? ret

GLScene:
? ? push dword 000004000h | 000000100h ; GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
? ? call glClear
? ? call glLoadIdentity
? ? push dword 0C0C00000h
? ? push dword 0
? ? push dword 0
? ? call glTranslatef
? ? push dword 9? ? ; GL_POLYGON
? ? call glBegin
? ? ? ? push dword 0
? ? ? ? push dword 3F800000h
? ? ? ? push dword 0BF800000h
? ? ? ? call glVertex3f
? ? ? ? push dword 0
? ? ? ? push dword 3F800000h
? ? ? ? push dword 3F800000h
? ? ? ? call glVertex3f
? ? ? ? push dword 0
? ? ? ? push dword 0BF800000h
? ? ? ? push dword 3F800000h
? ? ? ? call glVertex3f
? ? ? ? push dword 0
? ? ? ? push dword 0BF800000h
? ? ? ? push dword 0BF800000h
? ? ? ? call glVertex3f
? ? call glEnd
? ? call glFlush
? ? push dword
? ? call SwapBuffers
? ? ret
? ?
section .data

%include "win32n.inc"

ClassName: db "OpenGL", 0
WndName: db "Opengl ", 0
hwnd: dd 0
hdc: dd 0
hrc: dd 0
pixform: dd 0

qword1: dq -1.0
qword2: dq 0.0
qword3: dq 1.0

pfd:
istruc PIXELFORMATDESCRIPTOR
at PIXELFORMATDESCRIPTOR.nSize, dw PIXELFORMATDESCRIPTOR_size
at PIXELFORMATDESCRIPTOR.nVersion, dw 1
at PIXELFORMATDESCRIPTOR.dwFlags, dd 20h | 4 | 1
; PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER
at PIXELFORMATDESCRIPTOR.iPixelType, db 0 ; PFD_TYPE_RGBA
at PIXELFORMATDESCRIPTOR.cColorBits, db 24
at PIXELFORMATDESCRIPTOR.cRedBits, db 0
at PIXELFORMATDESCRIPTOR.cRedShift, db 0
at PIXELFORMATDESCRIPTOR.cGreenBits, db 0
at PIXELFORMATDESCRIPTOR.cGreenShift, db 0
at PIXELFORMATDESCRIPTOR.cBlueBits, db 0
at PIXELFORMATDESCRIPTOR.cBlueShift, db 0
at PIXELFORMATDESCRIPTOR.cAlphaBits, db 0
at PIXELFORMATDESCRIPTOR.cAlphaShift, db 0
at PIXELFORMATDESCRIPTOR.cAccumBits, db 0
at PIXELFORMATDESCRIPTOR.cAccumRedBits, db 0
at PIXELFORMATDESCRIPTOR.cAccumGreenBits, db 0
at PIXELFORMATDESCRIPTOR.cAccumBlueBits, db 0
at PIXELFORMATDESCRIPTOR.cAccumAlphaBits, db 0
at PIXELFORMATDESCRIPTOR.cDepthBits, db 16
at PIXELFORMATDESCRIPTOR.cStencilBits, db 8
at PIXELFORMATDESCRIPTOR.cAuxBuffers , db 0
at PIXELFORMATDESCRIPTOR.iLayerType, db 0 ; PFD_MAIN_PLANE
at PIXELFORMATDESCRIPTOR.bReserved, db 0
at PIXELFORMATDESCRIPTOR.dwLayerMask, dd 0
at PIXELFORMATDESCRIPTOR.dwVisibleMask, dd 0
at PIXELFORMATDESCRIPTOR.dwDamageMask, dd 0
iend

rect:
istruc RECT
iend

ps:
istruc PAINTSTRUCT
iend

wc:
istruc WNDCLASS
at WNDCLASS.style, dd 0
at WNDCLASS.lpfnWndProc, dd WndProc
at WNDCLASS.cbClsExtra, dd 0
at WNDCLASS.cbWndExtra, dd 0
at WNDCLASS.hInstance, dd 0
at WNDCLASS.hIcon, dd 0
at WNDCLASS.hCursor, dd 0
at WNDCLASS.hbrBackground, dd COLOR_BTNFACE+1
at WNDCLASS.lpszMenuName, dd 0
at WNDCLASS.lpszClassName, dd ClassName
iend

msg:
istruc MSG
at MSG.hwnd, dd 0
at MSG.message, dd 0
at MSG.wParam, dd 0
at MSG.lParam, dd 0
at MSG.time, dd 0
at MSG.pt, dd pt
iend

pt:
istruc POINT
at POINT.x, dd 0
at POINT.y, dd 0
iend


And the makefile:

@echo off
echo nasmw -fobj %1.asm
nasmw -fobj %1.asm
echo alink -c -oPE -entry _main %1.obj opengl32.lib win32.lib
alink -c -oPE -entry _main %1.obj opengl32.lib win32.lib


ps. rea: this was absolutely not what i was looking for, thanks anyway :-)
Posted on 2005-06-23 15:30:06 by deuter
Hi, I don't mean to be rude, but does NASM not support some HLL features like invoke or writing floating point properly (as opposed to in hex). If not then I really suggest you try an Assembler like FASM cause you're unlikly to get ar with OGL if you've to write every float in hex.
Posted on 2005-06-23 15:52:43 by Eóin
Yep, nasm does support invoke but it's hard to write in macros
I am familiar with nasm and use it every day, i've created an extra program "compiller" that runs nasm, gorc and linker by one keypress. So you can compile to gui, con, obj, dll or append the latest obj file to static library (using ms link.exe)
As ide i use Cromson Editor (screen, tool-menu and syntax-coloring included)

So, i've preselected some includes and samples with macros to use invoke, cdecl, COM calls and for creating COM classes
Not all is docummented

also:
invoke MessageBoxA, 0, "body", "caption", 0 // it's external call to __imp_*
or simply: MessageBox 0, "body", "caption", 0

call mysub, param1, param2 ... // direct call
cdecl param1, param2 ... // direct call to external fn
__cdecl param1, param2 ... // direct call to external __imp_*
com_call pointer, method, param1, param2 ... // see in GetDxVersion.asm

tools: push esi,edi,ebx //alloved

//writing classes (com subs)

CLASS cTest
? STDMETHOD Message , fnMessage // method_name, local_sub
? ...
ENDCLASS

main:
CALL_COM ITest, ITest_Message, "MmmEeeeSsssSssAaaaGggEeee"
? ...

COMSUB fnMessage, lpString
? ?MessageBox 0, lpString, "", 0
? ?%undef lpString // required if lpString used in other subs
ENDCOM


// standard functions

SUB mysub, param1, param2 ....
? ?UINT var1, var2? // sub esp,8
? ?UINT var3, var4? // again sub esp,8 !
...
? %undef param1, param2, var1 .... // don't forget
ENDSUB


PROC myproc, 16, param1, param2 .... // 16-stack frame
? ?UINT var1, var2? // sub esp,8 not inserted
? ?UINT var3, var4? // -||-
...
? ?%undef ...
ENDSUB



so if you have more questions... ask :D
http://rapidshare.de/files/2698438/nasm_inc.zip.html 2.7MB

the file is large because i've included too many interface declarations :)
________
does anybody know how to prevent nasm to do not merge all constanst names (equ, %define and %assign)? to .obj?
Posted on 2005-06-24 06:56:47 by sapero