Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: ninogenio on November 04, 2006
-
heres something ive been tinkering with for a little while its a plug in dll that uses opengl it has a few comands to make life a little easyer ive included the source for the dll as well as a few examples.
note: should now compile under 0.16b also if you wish to compile the dll using my make.bat file you will have to set you enviroment variables up.
v0.2
http://www.4shared.com/file/5530439/3b45b858/my_opengl_dll.html
v0.3
http://www.4shared.com/file/5684870/51c9e874/my_opengl_dllv03.html
added: v0.3
camera entitys are now possible you can add multiple cameras and jump between them
also camera can be moved and rotated
fixed a bug with the lighting that meant multiple lights were not possible
added a help grid for bulding stuff out of primitives
added examples to reflect new stuff
-------------------------------------------------------------------------------------------------------------------------
added: v0.2
light entitys although its a bit rough it works.
also added a proper initilize func that goes into diffrent reses
now with the init func you can window and the engine takes care of the mouse pointer
text func now works
gave everything a bit of a tidy
i will be updating this regularaly and also im going to write a readme up with instructions on usage.
should be ok to start messing around with now if any buggs are found please report ;)
-
Cool stuff, had a look through it but as I'm still using .16 atm I've not had a chance to run it. FB is needing stuff like this.
-
Props, thanks for sharing Nino.
-
cheers guys ive just updated this please read notes:
-
updated again :) check the first post for details.
-
This looks quite interesting. I may have to play around with some GL stuff now. :)
-
cheers rdc yeah im shure youll pick gl up no problem this is my first reall project in gl and its no to hard in saying that though its not that great either ;D
ohh yeah before i forget i updated the 0.3 link as there was a bug in the camera system and it got screwed up anywho the camera example is quite cool now so if you guys wish give it a check.
-
I'll grab it now. Thanks for all the hard work.
-
It's nice to see you having a go at an engine nino. One thing I would suggest is that you have a lot of hard-wired code there for generating (or just drawing) cubes and other shapes. Why not come up with some types that could hold any kind of object, and instead of re-working all the points every frame, pre-store the objects into these types and have a single routine that can render any shape from the data? That way you gain an enormous amount of flexibility and can add shapes and other models just by adding data instead of having to re-code everything each time.
Jim
-
im not quite sure what you mean jim i have a lot of hardwired cude for generating the data into my new_entity type but the main goal for the objects is that all of them get stored in that type and run through the one draw func.
wait do you mean something like a stack that lots of objects can be added to then at render time it goes down the stack draw all the objects stored there?
ive got a few questions ive been trying to add a upward and downward rotation function and also a move up and movedown function buti just cant quite get it right here what im trying?
sub PitchView( entity as new_camera_entity ptr , byval speed as double ) export
dim myVector as camera_vector
dim myVector as camera_vector
myVector.y = entity->mView->y - entity->mPos->y
myVector.z = entity->mView->z - entity->mPos->z
entity->mView->z = cast( double , ( entity->mPos->z + sin( speed / 3.14159 )*myVector.y + cos( speed / 3.14159 )*myVector.z) )
entity->mView->y = cast( double , ( entity->mPos->y + cos( speed / 3.14159 )*myVector.y - sin( speed / 3.14159 )*myVector.z) )
end sub
sub VStrafeCamera( entity as new_camera_entity ptr , byval speed as double ) export
dim myVector as camera_vector
dim myOrthoVector as camera_vector
myVector.y = entity->mView->y - entity->mPos->y
myVector.z = entity->mView->z - entity->mPos->z
myOrthoVector.y = -myVector.z
myOrthoVector.z = myVector.y
entity->mPos->y += myOrthoVector.y * speed
entity->mPos->z += myOrthoVector.z * speed
entity->mView->y += myOrthoVector.y * speed
entity->mView->z += myOrthoVector.z * speed
end sub
they look ok to me and to an extent the do work but dependent on the x positions of the camera the can slow down or even flip directions.
-
To move left and right do something like this,
camera_matrix [3][3];
left right
camera_pos.x += camera_matrix[0][0]*speed;
camera_pos.y += camera_matrix[0][1]*speed;
camera_pos.z += camera_matrix[0][2]*speed;
up down
camera_pos.x += camera_matrix[1][0]*speed;
camera_pos.y += camera_matrix[1][1]*speed;
camera_pos.z += camera_matrix[1][2]*speed;
forward back
camera_pos.x += camera_matrix[2][0]*speed;
camera_pos.y += camera_matrix[2][1]*speed;
camera_pos.z += camera_matrix[2][2]*speed;
You might have to change
[2][0]
[2][1]
[2][2]
to
- [2]
[1][2]
[2][2]
etc. depending how you store your matrices.
Jim
-
right cheers jim i got the camera going in all directions now!
back to what you were saying about the objects im curious did you mean when you said hardwired stuff like this.
function gl_textured_2d_quad( texture as GLuint , byval x1 as single , byval y1 as single , byval x2 as single , byval y2 as single ) export
glenable GL_TEXTURE_2D
glBindTexture GL_TEXTURE_2D,texture
glDisable GL_DEPTH_TEST
glMatrixMode GL_PROJECTION
glPushMatrix
glLoadIdentity
glOrtho 0, 800, 0, 600,-1, 1
glMatrixMode GL_MODELVIEW
glPushMatrix
glLoadIdentity
glBegin GL_QUADS
glTexCoord2f 0.0 , 0.0 : glVertex2f x1, y1
glTexCoord2f 1.0 , 0.0 : glVertex2f x2, y1
glTexCoord2f 1.0 , 1.0 : glVertex2f x2, y2
glTexCoord2f 0.0 , 1.0 : glvertex2f x1, y2
glEnd
glMatrixMode GL_PROJECTION
glPopMatrix
glMatrixMode GL_MODELVIEW
glPopMatrix
glEnable GL_DEPTH_TEST
gldisable GL_TEXTURE_2D
return 0
end function
function gl_2d_quad(byval x1 as single , byval y1 as single , byval x2 as single , byval y2 as single) export
glDisable GL_DEPTH_TEST
glMatrixMode GL_PROJECTION
glPushMatrix
glLoadIdentity
glOrtho 0 , 800 , 0 , 600 , -1 , 1
glMatrixMode GL_MODELVIEW
glPushMatrix
glLoadIdentity
glBegin GL_QUADS
glVertex2f x1, y1
glVertex2f x2, y1
glVertex2f x2, y2
glvertex2f x1, y2
glEnd
glMatrixMode GL_PROJECTION
glPopMatrix
glMatrixMode GL_MODELVIEW
glPopMatrix
glEnable GL_DEPTH_TEST
return 0
end function
function gl_textured_box() export
glBegin GL_QUADS
glTexCoord2f 0.0, 0.0 : glVertex3f -1.0, -1.0, 1.0
glTexCoord2f 1.0, 0.0 : glVertex3f 1.0, -1.0, 1.0
glTexCoord2f 1.0, 1.0 : glVertex3f 1.0, 1.0, 1.0
glTexCoord2f 0.0, 1.0 : glVertex3f -1.0, 1.0, 1.0
glTexCoord2f 1.0, 0.0 : glVertex3f -1.0, -1.0, -1.0
glTexCoord2f 1.0, 1.0 : glVertex3f -1.0, 1.0, -1.0
glTexCoord2f 0.0, 1.0 : glVertex3f 1.0, 1.0, -1.0
glTexCoord2f 0.0, 0.0 : glVertex3f 1.0, -1.0, -1.0
glTexCoord2f 0.0, 1.0 : glVertex3f -1.0, 1.0, -1.0
glTexCoord2f 0.0, 0.0 : glVertex3f -1.0, 1.0, 1.0
glTexCoord2f 1.0, 0.0 : glVertex3f 1.0, 1.0, 1.0
glTexCoord2f 1.0, 1.0 : glVertex3f 1.0, 1.0, -1.0
glTexCoord2f 1.0, 1.0 : glVertex3f -1.0, -1.0, -1.0
glTexCoord2f 0.0, 1.0 : glVertex3f 1.0, -1.0, -1.0
glTexCoord2f 0.0, 0.0 : glVertex3f 1.0, -1.0, 1.0
glTexCoord2f 1.0, 0.0 : glVertex3f -1.0, -1.0, 1.0
glTexCoord2f 1.0, 0.0 : glVertex3f 1.0, -1.0, -1.0
glTexCoord2f 1.0, 1.0 : glVertex3f 1.0, 1.0, -1.0
glTexCoord2f 0.0, 1.0 : glVertex3f 1.0, 1.0, 1.0
glTexCoord2f 0.0, 0.0 : glVertex3f 1.0, -1.0, 1.0
glTexCoord2f 0.0, 0.0 : glVertex3f -1.0, -1.0, -1.0
glTexCoord2f 1.0, 0.0 : glVertex3f -1.0, -1.0, 1.0
glTexCoord2f 1.0, 1.0 : glVertex3f -1.0, 1.0, 1.0
glTexCoord2f 0.0, 1.0 : glVertex3f -1.0, 1.0, -1.0
glEnd
return 0
end function
function gl_box() export
glBegin GL_QUADS
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
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
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
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
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
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
return 0
end function
as this is due to be removed now as its not needed anymore it was for inital debugging only.
the way the engine now works is that all objects get stored in the new_entity type regardless of wether there 3ds or static primitives and then they can be run through my one drawing routine .