Author Topic: opengl+nasm  (Read 16652 times)

nobody

  • Guest
opengl+nasm
« on: June 19, 2005, 07:59:50 PM »
Hello! How should I compile a program that's using opengl (what libraries and how to link it all together)? Thanks

ps. for example how to copile this: http://www.technocage.com/~ray/code/asm/nasm/Win32/triangle.asm ?

nobody

  • Guest
Re: opengl+nasm
« Reply #1 on: June 26, 2005, 05:34:20 PM »
> How should I compile a program that's using
> opengl

You can use the following command line:

NASM -fwin32 triangle.asm

and you will get a coff program.obj file.

You will need some libraries:
kernel32.lib, opengl32.lib and glut32.lib
http://www.xmission.com/~nate/glut.html

To get your triangle.exe file you can use the
Microsoft Linker:

LINK /entry:main /SUBSYSTEM:WINDOWS /VERSION:4.0 glut32.lib opengl32.lib kernel32.lib triangle.obj

You can get the kernel32.lib,opengl32.lib and
LINK.EXE from the Hutch's MASM32 distribution.
http://www.masm32.com/masmdl.htm

The sample (triangle.asm) that you point needs
to change the code in the entry so:

extern   _GetCommandLineA@0

; ...

_main:
   call   _GetCommandLineA@0
   mov   [esp+8], eax
   lea   eax, [esp+8]
   push   eax         ; push argv
   mov   dword [esp+8], 1
   lea   eax, [esp+8]
   push   eax         ; get addr of argc (offset changed :-)
   call   _glutInit@8      ; glutInit(&argc, &argv)

nobody

  • Guest
Re: opengl+nasm
« Reply #2 on: September 28, 2005, 02:48:28 PM »
&& under linux?

Thanks4All

nobody

  • Guest
Re: opengl+nasm
« Reply #3 on: October 03, 2005, 04:53:53 PM »
; ----------------------------------------------------------------------------
; triangle.asm
;
; A very simple *Linux* opengl application using the glut library.  it
; draws a nicely colored triangle in a top-level application window.
; Version of numit_or: numit_or@cantv.net
;
; Compile with:
;    nasm -felf triangle.asm -o triangle.o
;    gcc triangle.o -o triangle -L/usr/X11R6/lib -lGL -lglut -lglu
;
; you can find nasm in:
;   http://nasm.sourceforge.net/
;
; ----------------------------------------------------------------------------
;
; libGL is in
;    libMesaGL1 pack (Mandrake)
;   mesag3 - mesag-dev - mesa-common-dev packs (Debian)
; libglut and libGLU are in:
;    libMesaglut pack (Mandrake)
;   freeglut3 - freeglut3-dev - libglut3 - libglut3-dev (Debian)
;
; ----------------------------------------------------------------------------
   global   main
   extern   glClear
   extern   glBegin
   extern   glEnd
   extern   glColor3f
   extern   glVertex3f
   extern   glFlush
   extern   glutInit
   extern   glutInitDisplayMode
   extern   glutInitWindowPosition
   extern   glutInitWindowSize
   extern   glutCreateWindow
   extern   glutDisplayFunc
   extern   glutMainLoop

GL_COLOR_BUFFER_BIT   equ    16384
GL_POLYGON      equ   9

section   .data
title   db   'A Simple Triangle', 0
zero   dd   0.0
one   dd   1.0
half   dd   0.5
neghalf dd   -0.5

section .text
display:
   push   dword GL_COLOR_BUFFER_BIT
   call   glClear         ; glClear(GL_COLOR_BUFFER_BIT)
   add   esp, 4
   push   byte GL_POLYGON
   call   glBegin         ; glBegin(GL_POLYGON)
   add   esp, 4
   push   byte 0
   push   byte 0
   push   dword [one]
   call   glColor3f      ; glColor3f(1, 0, 0)
   add   esp, 12
   push   byte 0
   push   dword [neghalf]
   push   dword [neghalf]
   call   glVertex3f      ; glVertex(-.5, -.5, 0)
   add   esp, 12
   push   byte 0
   push    dword [one]
   push   byte 0
   call   glColor3f      ; glColor3f(0, 1, 0)
   add   esp, 12
   push   byte 0
   push   dword [neghalf]
   push   dword [half]
   call   glVertex3f      ; glVertex(.5, -.5, 0)
   add   esp, 12
   push   dword [one]
   push   byte 0
   push   byte 0
   call   glColor3f      ; glColor3f(0, 0, 1)
   add   esp, 12
   push   byte 0
   push   dword [half]
   push   byte 0
   call   glVertex3f      ; glVertex(0, .5, 0)
   add   esp, 12
   call   glEnd         ; glEnd()
   call   glFlush         ; glFlush()
   ret

main:
   push   ebp
   mov   ebp, esp
   push   dword [ebp+12]
   lea   eax, [ebp+8]
   push   eax
   call   glutInit
   push   byte 0
   call   glutInitDisplayMode
   add   esp, 4
   push   dword 80
   push   dword 80
   call   glutInitWindowPosition
   add   esp, 8
   push   dword 300
   push   dword 400
   call   glutInitWindowSize
   add   esp, 8
   push   title
   call   glutCreateWindow
   add   esp, 4
   push   display
   call   glutDisplayFunc
   call   glutMainLoop
   leave
   ret

-----------------
nmt