Basic 3D Screen

BlitzMax Forums/BlitzMax Beginners Area/Basic 3D Screen

I'm a bit short on time atm but can someone throw down some basic code to init a 3d 1024x768 screen and how you'd go about making a skybox?

Chroma, Do you mean in native Blitzmax (i.e. no 3D module yet) or using the OGL side of Blitzmax?

See the OpenGL forum, it should have something that sets up a basic display.

I know people are doing basic 3d stuff like loading models and goofing off. What method are people using? And how does it look like in code?

They're using raw OGL accessed through the Bmx interface...
For OGL code check these tutorials...
here

Ugh...Call me an old timer. It all seems over-complex now. =(

/duck

Can someone throw down a basic program here that initiates a 3d screen and puts a simple spinning cube on the screen?

Check the project board out for the Nehe Tutorial :)

This will help you understanding this "over complexiness"

Can someone post something that does something like the following? Or does anyone actually know how to do it? lol

In Blitz3D
Graphics3d 1024,768,32,2
Setbuffer Backbuffer()

light = CreateLight()
camera = CreateCamera()
cube = CreateCube()
PositionEntity cube,0,0,10

While Not Keyhit(1)
cls

Updateworld
Renderworld

Flip
Wend



In BlitzMax
'umm....no idea
'hmmm...maybe
bglCreateContext(1024,768,32,0,BGL_BACKBUFFER | BGL_DEPTHBUFFER)
InitGl()

'There's a start even though it's a bit weird
'Here's some more

While Not Keyhit(KEY_ESCAPE)

bglDrawText("Hey I'm trying ok? :p",10,24)
FlushMem
bglSwapBuffers
Wend



If you want to do it in OpenGL yourself you should read the OpenGL manuals to learn how it all works. It's worth the effort.

nehe is the place to start

Checked out NeHe and nothing against the creators, etc....but it just seems a bit shoddy.

I haven't been keeping up on what's going on with an OGL 3D module for BMax but is Mark planning on making one that will actually be user friendly and be optimized for maximum performance with BMax?

according to his worklog, it will be out in about 6 months as regards syntax and performance, I'm unsure. But I would expect it to be good.

When I downloaded BMax I was initially a bit lost because at the moment some things seem a bit vague (Initializing a basic 3D screen and throwing a cube on screen for instance). I like to get right into making the game and not worrying about making or locating a bunch of dlls/libs/functions to make it work. Letting the community have the ability to make a bunch of plugs/modules is terrific. But I'm hoping a lot more will be natively built into BMax so making the game part can be easy as it was before.

Multiplayer for example. Where is it? Maybe I just haven't read the docs thoroughly enough.

network module is on it's way, but there is basic socket support with the undocumented TSocketStream (brl.mod/socketstream.mod/socketstream.bmx]

here's a quick example of how to grab a web page via port 80 with it:
stream : TSocketStream = TSocketStream.CreateClient("www.blitzbasic.com", 80)
If Not stream Then
	RuntimeError("Error creating socket")
EndIf

If Not stream Return

	stream.WriteLine "GET / HTTP/1.1"
	stream.WriteLine "Host: 127.0.0.1"
	stream.WriteLine ""

While Not Eof( stream )
	'If Not stream.ReadLine() Exit
	Print Stream.Readline()
Wend


stream.close()
stream = Null
FlushMem

End




You can already make games, the 2D module is working, no problem with it normally :)

I'm starting to think I'm gonna keep pluggin away with B3D until BMax is further along. I know Mark is working his a$$ off on it. I can't wait to harness the true power in a few months. I have some really cool ideas.

Dreamora...what did your name used to be?

Strict

Const Width=1024,Height=768

bglCreateContext(Width, Height, 32, 0,BGL_BACKBUFFER|BGL_DEPTHBUFFER)

glViewport(0,0,Width,Height)

glMatrixMode GL_PROJECTION
gluPerspective 45.0,Float(Width)/Float(Height),1.0,1000.0

Type color
 Field r#,g#,b#,a#
End Type

Type vec3
 Field x#,y#,z#
End Type

Local ambient:color = New color
ambient.r = 0.2
ambient.g = 0.5
ambient.b = 0.7

Local position:vec3 = New vec3
position.x = 1.0
position.y = 3.0
position.z = 5.0

glLightfv GL_LIGHT0, GL_AMBIENT, Varptr(ambient.r)
glLightfv GL_LIGHT0, GL_POSITION, Varptr(position.x)
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glShadeModel(GL_SMOOTH)
glEnable(GL_DEPTH_TEST)
glEnable(GL_CULL_FACE)

glMatrixMode GL_MODELVIEW    
glTranslatef(0.0,0.0,-10.0)

While Not KeyHit(KEY_ESCAPE)

 glRotatef(0.03,0,1,0)
 glRotatef(0.02,1,0,0)
 glRotatef(-0.01,0,0,1)

 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

 glBegin(GL_QUADS)

  'Front
  glNormal3f( 0.0,0.0,-1.0)
  glVertex3f(-1.0, 1.0,-1.0)
  glVertex3f( 1.0, 1.0,-1.0)
  glVertex3f( 1.0,-1.0,-1.0)
  glVertex3f(-1.0,-1.0,-1.0)

  'Back
  glNormal3f( 0.0, 0.0, 1.0)
  glVertex3f(-1.0, 1.0, 1.0)
  glVertex3f(-1.0,-1.0, 1.0)
  glVertex3f( 1.0,-1.0, 1.0)
  glVertex3f( 1.0, 1.0, 1.0)

  'Right
  glNormal3f( 1.0, 0.0, 0.0)
  glVertex3f( 1.0, 1.0,-1.0)
  glVertex3f( 1.0, 1.0, 1.0)
  glVertex3f( 1.0,-1.0, 1.0)
  glVertex3f( 1.0,-1.0,-1.0)

  'Left
  glNormal3f(-1.0, 0.0, 0.0)
  glVertex3f(-1.0, 1.0,-1.0)
  glVertex3f(-1.0,-1.0,-1.0)
  glVertex3f(-1.0,-1.0, 1.0)
  glVertex3f(-1.0, 1.0, 1.0)

  'Top
  glNormal3f( 0.0, 1.0, 0.0)
  glVertex3f(-1.0, 1.0,-1.0)
  glVertex3f(-1.0, 1.0, 1.0)
  glVertex3f( 1.0, 1.0, 1.0)
  glVertex3f( 1.0, 1.0,-1.0)

  'Bottom
  glNormal3f( 0.0,-1.0, 0.0)
  glVertex3f( 1.0,-1.0, 1.0)
  glVertex3f(-1.0,-1.0, 1.0)
  glVertex3f(-1.0,-1.0,-1.0)
  glVertex3f( 1.0,-1.0,-1.0)

 glEnd()

 bglSwapBuffers()

Wend



End



Dreamora
haven't changed mine

Multiplayer for example. Where is it?
Just like the 3D module, the GUI module and the DX7 2D fallback module, the Multiplayer module is not finished yet.

Who is making these modules?

Also the code Sweenie supplied is horrific(not your fault) compared to cube=CreateCube(). I hope Mark isn't reading this and wanting to shoot me. I hope everyone is getting/got what they wanted from the new BMax. I'm just hoping you don't need to be a rocket scientist to use it(ie. puting a cube on the screen and spinning it).

Who is making these modules?
Blitz Research Ltd.

Also the code Sweenie supplied is horrific(not your fault) compared to cube=CreateCube().
Yes. The code Sweenie supplied is low-level OpenGL code which is currently, that is until the 3D module is finished, the only way to do 3D in BlitzMAX. If you don't want to bother with low-level OpenGL stuff, and/or want to use the same sourcecode and be able to use a DirectX9 fallback on Windows platforms, then I suggest you wait for the official 3D module.

I'm just hoping you don't need to be a rocket scientist to use it(ie. puting a cube on the screen and spinning it).
No. I'm sure the BlitzMAX 3D module will be at least as abstract as Blitz3D is - even tho' it's dealing with more complex issues.

Well that is great news. I guess that gives me plenty of time to work on my game design. =)