Hello
I have translate the NeHe tutorial #13 to PB.
You can finde it here
NeHe lesson 13 for PureBasic
Best regards,
Nico
OpenGL Nehe tutorial 13 for PB
-
- Enthusiast
- Posts: 372
- Joined: Sun Apr 03, 2005 2:14 am
- Location: England
Hi nicolaus,
Just started playing with your various tutorials. Awesome, and thanks.
With this tutorial I am obviously missing something because I get a problem with this line:Perhaps you can help me and tell me what I am missing? (The others - 9 to earth - run ok).
Again, congrats!
Just started playing with your various tutorials. Awesome, and thanks.
With this tutorial I am obviously missing something because I get a problem with this line:
Code: Select all
glClearDepth__(1.0)
Again, congrats!

@}--`--,-- A rose by any other name ..
@Dare2
You have to ways to kill your prob with glClear__(). First you install the glWrapper lib from traumatic.
The second way is that you overwrite the code with this code:
Normal glClear want have a double value. In the lib from traumatic you can add normal floats. In this code i have change it to the normal function of OpenGl (wat want double value) and have add a procedure to change float to double. The procedure to change flot to double is orginal by remi_meier.
Hope that you can run this tutorial now.
Nico
You have to ways to kill your prob with glClear__(). First you install the glWrapper lib from traumatic.
The second way is that you overwrite the code with this code:
Code: Select all
;*****************************************
;* NeHe Tutorial Lesson 13 for PureBasic *
;* This Code Was Created By Nico Gruener *
;* 09.10.2005 *
;* Orginal by Nehe http://nehe.gamedev.net
;*****************************************
; Note. to compiled this code you must have installet the glWrapper userlib for PureBasic by traumatic.
; you finde this on www.purearea.net
XIncludeFile "OpenGL.pb"
#ANTIALIASED_QUALITY = 4
#WindowWidth = 640
#WindowHeight = 480
#WindowFlags = #PB_Window_TitleBar | #PB_Window_MaximizeGadget |#PB_Window_SystemMenu | #PB_Window_MinimizeGadget |#PB_Window_ScreenCentered
Global base.l
Global hDC.l
Global hrc.l
Global cnt1.f
Global cnt2.f
Global hwnd
Global Quit.l
Global FPS,Zeit
Global FPS_s.s
Quit = 0
Structure DOUBLE_
l.l
h.l
EndStructure
Procedure OGLDFloat2Double(*d.DOUBLE_, f.f)
!MOV eax, dword[esp]
!FLD dword[esp+4]
!FSTP qword[eax]
EndProcedure
Procedure MyWindowCallback(WindowId, message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
If message = #WM_SIZE
UseWindow(0)
glViewport_(0, 0, WindowWidth(), WindowHeight())
Result = 1
EndIf
ProcedureReturn Result
EndProcedure
Procedure BuildGL_Font(FontHeight.l,FontName.s)
Protected font,oldfont
base = glGenLists_(96) ; Storage For 96 Characters
; now we create the font
font = CreateFont_(-FontHeight,0,0,0,#FW_NORMAL,#False,#False,#False,#ANSI_CHARSET,#OUT_TT_PRECIS,#CLIP_DEFAULT_PRECIS,#ANTIALIASED_QUALITY,#FF_DONTCARE|#DEFAULT_PITCH,FontName)
oldfont = SelectObject_(hDC, font) ; Selects The Font We Want
wglUseFontBitmaps_(hDC, 32, 96, base) ; Builds 96 Characters Starting At Character 32
SelectObject_(hDC, oldfont) ; Selects The Font We Want
DeleteObject_(font) ; Delete The Font
EndProcedure
Procedure KillGL_Font()
glDeleteLists_(base, 96) ; Delete All 96 Characters
EndProcedure
Procedure PrintGL_Text(Txt.s)
glPushAttrib_(#GL_LIST_BIT) ; Pushes The Display List Bits
glListBase_(base - 32) ; Sets The Base Character to 32
glCallLists_(Len(Txt),#GL_UNSIGNED_BYTE,Txt) ; Draws The Display List Text
glPopAttrib_()
EndProcedure
Procedure DeinitOpenGL()
KillGL_Font()
If hrc
wglMakeCurrent_(#Null,#Null)
wglDeleteContext_(hrc)
EndIf
If hDC
ReleaseDC_(hwnd,hDC)
EndIf
EndProcedure
If OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, #WindowFlags,"NeHe Lesson 13 for PureBasic")
SetWindowCallback(@MyWindowCallback())
hwnd = WindowID(0)
hDC = GetDC_(hwnd)
;Initialize OpenGL
pfd.PIXELFORMATDESCRIPTOR
pfd\nSize = SizeOf(PIXELFORMATDESCRIPTOR)
pfd\nVersion = 1
pfd\dwFlags = #PFD_SUPPORT_OPENGL | #PFD_DOUBLEBUFFER | #PFD_DRAW_TO_WINDOW
pfd\iLayerType = #PFD_MAIN_PLANE
pfd\iPixelType = #PFD_TYPE_RGBA
pfd\cColorBits = 24
pfd\cDepthBits = 32
pixformat = ChoosePixelFormat_(hDC, pfd)
SetPixelFormat_(hDC, pixformat, pfd)
hrc = wglCreateContext_(hDC)
wglMakeCurrent_(hDC, hrc)
SwapBuffers_(hDC)
glshademodel_(#GL_SMOOTH) ; Enable Smooth Shading
glClearColor_(0.0, 0.0, 0.0, 0.5) ; Black Background
OGLDFloat2Double(ClearDepth.DOUBLE_,1.0)
glClearDepth_(ClearDepth\l,ClearDepth\h); Depth Buffer Setup
glEnable_(#GL_DEPTH_TEST) ; Enables Depth Testing
glDepthFunc_(#GL_LEQUAL) ; The Type Of Depth Testing To Do
glHint_(#GL_PERSPECTIVE_CORRECTION_HINT,#GL_NICEST); // Really Nice Perspective Calculations
BuildGL_Font(24,"Courier New") ; build the font. show in the procedure to know wat we do
EndIf
Repeat
Event = WindowEvent()
If GetTickCount_() < Zeit + 1000
FPS + 1
Else
FPS_s = Str(FPS)
FPS = 0
Zeit = GetTickCount_()
EndIf
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT) ; Clear Screen And Depth Buffer
glLoadIdentity_() ; Reset The Current Modelview Matrix
glTranslatef_(0.0,0.0,1.0) ; Move One Unit Into The Screen
; Pulsing Colors Based On Text Position
glColor3f_(1.0*(Cos(cnt1)),1.0*(Sin(cnt2)),1.0-0.5*(Cos(cnt1+cnt2)))
; Position The Text On The Screen
glRasterPos2f_(-0.45+0.05*(Cos(cnt1)),0.32*(Sin(cnt2)))
PrintGL_Text("Active OpenGL Text With NeHe") ; Print GL Text To The Screen
glRasterPos2f_(-0.85+0.05*(Cos(cnt1)),0.65*(Sin(cnt2)))
PrintGL_Text("FPS: "+FPS_s)
cnt1+0.051 ; Increase The First Counter
cnt2+0.005
SwapBuffers_(hDC)
If Event = #PB_Event_CloseWindow
DeinitOpenGL()
Quit = 1
EndIf
Until Quit = 1
Hope that you can run this tutorial now.
Nico
my live space