porting NeHe's tutorial #2 to PB

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by clx.

I've been trying to get this right for a couple of days now but just can't seem to do it.. I've looked at the powerbasic source and tried to follow that also but still doesn't work. if anyone can help i'd appreciate it.. here's the code.

Code: Select all

IncludeFile "OpenGL.pbi"
Procedure InitGL()

glClearColor_(0.0, 0.0, 0.0, 0.0)
glDepthFunc_(#GL_LESS)
glEnable_(#GL_DEPTH_TEST)
glShadeModel_(#GL_SMOOTH)

glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()

gluPerspectivef_(45.0, 640/480, 0.1, 100.0)
glMatrixMode_(#GL_MODELVIEW)

EndProcedure


Procedure DrawScene(hDC)

glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity_()

glTranslatef_(-1.5, 0.0, -6.0)

glBegin_(#GL_TRIANGLES)
    glVertex3f_( 0.0, 1.0, 0.0)
    glVertex3f_(-1.0,-1.0, 0.0)
    glVertex3f_( 1.0,-1.0, 0.0)
glEnd_()

glTranslatef_(3.0,0.0,0.0)

glBegin_(#GL_QUADS)
    glVertex3f_(-1.0, 1.0, 0.0)
    glVertex3f_( 1.0, 1.0, 0.0)
    glVertex3f_( 1.0,-1.0, 0.0)
    glVertex3f_(-1.0,-1.0, 0.0)
glEnd_()

EndProcedure


pfd.PIXELFORMATDESCRIPTOR

hWnd = OpenWindow(0, 10, 10, 640, 480, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "OpenGL Test")

hdc = GetDC_(hWnd)

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   = 16   

pixformat = ChoosePixelFormat_(hdc, pfd)
SetPixelFormat_(hdc, pixformat, pfd)
hrc = wglCreateContext_(hdc)
wglMakeCurrent_(hdc,hrc)

InitGL()

While Quit = 0

  Repeat 
    EventID = WindowEvent()
    
    Select EventID
      Case #PB_EventCloseWindow
        Quit = 1
    EndSelect
  
  Until EventID = 0
  
  DrawScene(hDC)
  SwapBuffers_(hDC)

Wend
thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dmoc.

Works here so I think it may be your OpenGL.pbi. Here goes and sorry to all for the long post!

Edit: See next post!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Manolo.
Originally posted by dmoc

Works here so I think it may be your OpenGL.pbi. Here goes and sorry yo all for the long post!

; ** Copyright 1996 Silicon Graphics, Inc.
; ** All Rights Reserved.
; **
; ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
; ** the contents of this file may not be disclosed to third parties, copied or
; ** duplicated in any form, in whole or in part, without the prior written
; ** permission of Silicon Graphics, Inc.
Hi dmoc,

He, he, he, he...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by clx.

that's weird.. I only get a blank black screen. I used your OpenGL.pbi and the same thing happened, also tried upgrading my opengl drivers and still no luck. what else could be wrong?

thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dmoc.

Oops! But, eh, it IS public isn't it? But I better delete it just in case, shucks.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dmoc.

clx, what's your specs?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by clx.

you mean the source? you can keep it if you want.. I just want to figure out why nothing is showing up on the screen, I've tried other tutorials and always get a blank screen
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by clx.

oh ok I understood that wrong, you meant the OpenGL.pbi you posted? ok.

my specs..

p3 450mhz
ati Xpert 128 16mb vid card - latest opengl drivers
256 mb ram
purebasic 3.51
Windows XP pro
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dmoc.

Ummm, XP, didn't I read somewhere about OpenGL being removed from XP? I don't know because I don't have it. Can you run any other OpenGL progs, games perhaps? Maybe someone with XP might want to chip in?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by clx.

my drivers that XP used for my vid card didn't come with OpenGL drivers but I updated that along time ago. the spinning cube demo that fred(?) wrote works perfectly fine on my machine and I also play counter-strike in OpenGL mode so I don't think it's a problem with the drivers
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dmoc.

My only suggestion then is to check if you are actually getting your context.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by clx.

sorry but what do you mean by that?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by clx.

I just sent the compiled code to a friend and it worked fine on his win98 machine, has anyone tried it on Windows XP PRO? if you could help out I'd appreciate it.

thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by VPureBasic.

Hi all,

I tried the code and everthing will work well if you change this line...

glTranslatef_(-1.5, 0.0, -6.0)

to something like this...

glTranslatef_( 0, 0.0, -10.0)

You ask for a move on the sideX of -1.5... that's almost 1 and half of your screen for this type of view... that's why always black :wink:

Roger
( Wait an see... PureBasic will have its own Pure3D OpenGL Library soon... all written with PB by me )
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by clx.

strange, it still doesn't work on my machine with your code VPureBasic... arrgg this is really getting to me now. I'm thinking it has to do with my drivers or my video card. But running the ported tutorials on NeHe's website to other languages work perfectly fine except for when I try and convert them to purebasic. Like I said my friend was able to run the executable of my code I gave him perfectly fine, so I really think it has to do with my drivers/video card. I'll try and figure something out...

Thanks for the help guys.. :wink:
Post Reply