Making a pause menu in a 3D OpenGL application

User projects written in or related to FreeBASIC.
axipher
Posts: 891
Joined: Dec 27, 2005 16:37
Location: Sudbury,Ontario
Contact:

Making a pause menu in a 3D OpenGL application

Postby axipher » Mar 20, 2009 18:07

Hey everyone, I found some time between school work to work on my 3D world at this link.

http://www.freebasic.net/forum/viewtopic.php?p=113942#113942

I am currently trying to figure out how to add a pause menu to it, so it still draws the scene, and adds a overlayed menu on top with variable transparency. What would be the easiest way to accomplish this? Keeping in mind that the world is 3D that is mapped behind the menu.
DaveUnit
Posts: 239
Joined: Apr 20, 2006 15:47
Location: Central MA
Contact:

Postby DaveUnit » Mar 22, 2009 4:36

If by your question you mean how would you draw a menu then what you would need to do is do all your 3D drawing as normal, then setup an orthographic projection with something like gluOrtho2D() and do all the 2D menu drawing, and voila, a nice 2D overlay on top of a 3D scene.
axipher
Posts: 891
Joined: Dec 27, 2005 16:37
Location: Sudbury,Ontario
Contact:

Postby axipher » Mar 22, 2009 15:35

Ya, a 2D overlay is what I was thinking, do you maybe have a quick example of setting up the 2D orthographic plane? Now I'm asusming that I would have to re-setup the 3D part of the game after leaving the pause menu.
Landeel
Posts: 699
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Postby Landeel » Mar 22, 2009 17:33

Code: Select all


sub osgl_set2dscreen()

myscreen.rendermode=0



glViewport 0, 0, myscreen.realx, myscreen.realy

glMatrixMode GL_PROJECTION

glLoadIdentity

glOrtho myscreen.zoomx , myscreen.x-myscreen.zoomx , myscreen.y-myscreen.zoomy-myscreen.widescreenpixels , myscreen.zoomy+myscreen.widescreenpixels,-1,1                                '' Set Up An Ortho Screen

'gluPerspective 90, x/y, 3, .1

glMatrixMode GL_MODELVIEW

glLoadIdentity

glShadeModel GL_SMOOTH                   '' Enables Smooth Color Shading

glClearColor 0,0,0,0          '' Clear The Background Color To Black

'glBlendFunc GL_SRC_ALPHA, GL_ONE         '' Select The Type Of Blending

glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA

glEnable GL_BLEND                                      '' Enable Blending

glEnable GL_TEXTURE_2D                   '' Enable 2D Texture Mapping

glEnable GL_ALPHA_TEST

glAlphaFunc GL_GREATER, 0.001

'glAlphaFunc GL_GREATER, 0.5

glDisable GL_DEPTH_TEST



glEnable GL_COLOR_MATERIAL

glDisable GL_LIGHTING

glDisable GL_LIGHT1



end sub



sub osgl_set3dscreen()



myscreen.rendermode=1





   glViewport 0, 0, myscreen.realx, myscreen.realy

   glMatrixMode GL_PROJECTION                 '' Select The Projection Matrix

   glLoadIdentity                             '' Reset The Projection Matrix

   gluPerspective 45.0, myscreen.x/myscreen.y, 0.1, 100.0   '' Calculate The Aspect Ratio Of The Window

   glMatrixMode GL_MODELVIEW                  '' Select The Modelview Matrix

   glLoadIdentity                             '' Reset The Projection Matrix

glShadeModel GL_SMOOTH                   '' Enables Smooth Color Shading

'glClearColor 0.0, 0.0, 0.0, 0.0          '' Clear The Background Color To Black

glClearDepth 1.0                                   '' Enables Clearing Of The Depth Buffer

'glBlendFunc GL_SRC_ALPHA, GL_ONE         '' Select The Type Of Blending

glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA

glEnable GL_BLEND                                      '' Enable Blending

glEnable GL_TEXTURE_2D                   '' Enable 2D Texture Mapping

glEnable GL_ALPHA_TEST

glAlphaFunc GL_GREATER, 0.001

'glAlphaFunc GL_GREATER, 0.5

glEnable GL_DEPTH_TEST                              '' Enables Depth Testing

glDepthFunc(GL_LESS)                                '' The Type Of Depth Test To Do





'Dim Shared LightDiffuse(0 To 3) As Single => {3, 3, 3, 1}

LightDiffuse(0)=1:LightDiffuse(1)=1:LightDiffuse(2)=1:LightDiffuse(3)=1

glLightfv GL_LIGHT1, GL_DIFFUSE, @LightDiffuse(0)



'Dim Shared LightPosition(0 To 3) As Single => {0, 0, 0, 1}

LightPosition(0) = 0:LightPosition(1) = 0:LightPosition(2) = -5:LightPosition(3) = 1

glLightfv GL_LIGHT1, GL_POSITION, @LightPosition(0)



glEnable GL_COLOR_MATERIAL

glEnable GL_LIGHTING

glEnable GL_LIGHT1



end sub



This is a fragment of my code. I just use the subs to set the screen for 3D rendering, or 2D ortho for drawing text, sprites, etc.
Hope you find it useful.
axipher
Posts: 891
Joined: Dec 27, 2005 16:37
Location: Sudbury,Ontario
Contact:

Postby axipher » Mar 24, 2009 4:09

Thank you for your help, I have updated the program in the link in my first post with your method of making menus.

Return to “Projects”

Who is online

Users browsing this forum: MSN [Bot] and 1 guest