How do you create a main menu???

Started by
5 comments, last by pheonix2468 18 years, 7 months ago
I would like to know how to create a menu for the start of an opengl application. Maybe someone would be kind enough to post code to place in one of nehe's tutorials or point me in the direction of sites that have tutorials on doing opengl, c++ menu's. I am wanting the menu to have a start and an exit button. help would be greatly appreciated -=pheonix2468=-
Advertisement
Well, you could use something like this. There are other packages out there too that handle GUI's in OpenGL. Try google [smile].
If at first you don't succeed, redefine success.
i have done something really simple it uses only text
if you want you can

email me

and you i will send the requierd classes .
agian it is only main menu and nothing else
thanks for the replys :)
ive googled around but at the moment can't find one that suits my need's, so im going to tak bbb's advice and have a go at createing one myself. I don't want a full gui toolkit, i just want to how to change between scenes, let me explain.
Say i've got nehe's lesson 5. i know how to create quads and texture them, but how do i create a normall scene with, say a quad with a texture start(maybe not even needing a texture), and then check if the mouse is over the quad and the button pressed. Also how would i get it to draw the menu screen first and when the button is pressed draw the scene with a quad and/or a triangle in it.

I am trying to keep this as simple(and hopefully as easy) as possible to acheive the desired result.

Yet again help would be appreciated, and i hope this post has been more precise on what i am asking ( if not just say i will attempt to re-iterate)
-=pheonix2468=-
Thanks BBB that sounds like a good way to do it to me. Ill have a go myself first but if you could post or pm or e-mail me the code that would a great help as it would mean i would have some reference material.

One question ; doesn't overlapping the new scene hit on performance?? (im not really bothered, but just a question).

Thanks alot
-=pheonix2468=-
OK. right so here i have some code, it is a simple app with a torus, spheres, etc.
/* * FreeGLUT Shapes Demo * * Written by Nigel Stewart November 2003 * * This program is test harness for the sphere, cone  * and torus shapes in FreeGLUT. * * Spinning wireframe and smooth shaded shapes are * displayed until the ESC or q key is pressed.  The * number of geometry stacks and slices can be adjusted * using the + and - keys. */#include	<windows.h>							// Header File For Windows#include	<stdarg.h>							// Header File For Variable Argument Routines#include    <stdlib.h>#include    <stdio.h>					// Header File For Standard Input/Output#include	<gl\gl.h>							// Header File For The OpenGL32 Library#include	<gl\glu.h>							// Header File For The GLu32 Library#include	<gl\glaux.h>							// Header File For The Glaux Library#include    <GL\glut.h>static int slices = 50;static int stacks = 50;int xrot, yrot, zrot; int i;int ydownn = 3;/* GLUT callback Handlers */static void resize(int width, int height){    const float ar = (float) width / (float) height;        glViewport(0, 0, width, height);    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    glFrustum(-ar, ar, -1.0, 1.0, 2, 100.0);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity() ;    }static void display(void){    const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;    const double a = t*90.0;    const double b = t*120.0;    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);    glLoadIdentity();    glColor3d(0.0,0.0,0.8);ydownn = ydownn - 0.5;        glPushMatrix();        glRotated(a,0,0,1);        glTranslatef(0,1,-7);        glRotated(a,0,0,1);        glutSolidSphere(0.25,slices,stacks);    glPopMatrix();    glColor3d(0.0,1.0,0.0);    glPushMatrix();        glTranslatef(0,ydownn,-7);        glRotated(a,0,1,0);        glutSolidTorus(0.25,0.5,slices,stacks);    glPopMatrix();    glColor3d(1.0,0.0,1.0);        glPushMatrix();        glRotated(a,0,0,-1);        glTranslatef(0,1.5,-7);        glRotated(a,0,0,1);        glutSolidSphere(0.25,slices,stacks);    glPopMatrix();        glColor3d(1.0,1.0,0.0);        glPushMatrix();        glRotated(b,0,0,1);        glTranslatef(0,2,-7);        glRotated(a,0,0,1);        glutSolidSphere(0.25,slices,stacks);    glPopMatrix();        glColor3d(0.0,1.0,1.0);        glPushMatrix();        glRotated(b,0,0,-1);        glTranslatef(0,2.5,-7);        glRotated(a,0,0,1);        glutSolidSphere(0.25,slices,stacks);    glPopMatrix();        glColor3d(0,1,0);        glPushMatrix();        glTranslatef(3,3,-7);        glRotatef(a,1,0,0);        glRotated(a,0,0,1);        glutSolidCone(0.4,0.6,slices,stacks);    glPopMatrix();            glColor3d(0,0,1);        glPushMatrix();        glTranslatef(3,-3,-7);        glRotatef(b,1,0,0);        glRotated(b,0,0,1);        glutSolidCone(0.4,0.6,slices,stacks);    glPopMatrix();            glColor3d(1,1,0);        glPushMatrix();        glTranslatef(-3,-3,-7);        glRotatef(a,1,0,0);        glRotated(a,0,0,1);        glutSolidCone(0.4,0.6,slices,stacks);    glPopMatrix();            glColor3d(1,0,1);        glPushMatrix();        glTranslatef(-3,3,-7);        glRotatef(b,1,0,0);        glRotated(b,0,0,1);        glutSolidCone(0.4,0.6,slices,stacks);    glPopMatrix();    glPushMatrix();    glBegin(GL_QUADS);    glVertex3f(-6,4,-8);    glVertex3f(-6,-4,-8);    glVertex3f(6,-4,-8);    glVertex3f(6,4,-8);    glEnd();    glPopMatrix();    glutSwapBuffers();}static void key(unsigned char key, int x, int y){    switch (key)     {    // input to change stacks etc       case 27 :         case '[':            exit(0);            break;        case ']':            Sleep(2000);            break;        case '+':            slices++;            stacks++;            break;        case '-':            if (slices>3 && stacks>3)            {                slices--;                stacks--;            }            break;                }    glutPostRedisplay();}static void idle(void){    glutPostRedisplay();}const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat high_shininess[] = { 75.0f };/* Program entry point */int main(int argc, char *argv[]){    glutInit(&argc, argv);    glutInitWindowSize(640,480);    glutInitWindowPosition(0,0);    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);    glutCreateWindow("d3c1m8t0r v1.00");    glutReshapeFunc(resize);    glutDisplayFunc(display);    glutKeyboardFunc(key);    glutIdleFunc(idle);    glClearColor(1,0,0,1);    glEnable(GL_CULL_FACE);    glCullFace(GL_BACK);    glEnable(GL_DEPTH_TEST);    glDepthFunc(GL_LESS);    glEnable(GL_LIGHT0);    glEnable(GL_NORMALIZE);    glEnable(GL_COLOR_MATERIAL);    glEnable(GL_LIGHTING);    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);    glLightfv(GL_LIGHT0, GL_POSITION, light_position);    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);    glutMainLoop();    return EXIT_SUCCESS;}

So how do i add when say 'p' is pressed it cleares the buffer / swithches to ortho and other neccesary stuff. at a vague quick guess this is what i thought.
        case 'p':glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);    glLoadIdentity();    glBegin(GL_QUADS);    glVertex3f(-6,4,-8);    glVertex3f(-6,-4,-8);    glVertex3f(6,-4,-8);    glVertex3f(6,4,-8);    glEnd();    glutSwapBuffers();            break;

i haven't put in switching to ortho yet. ill look into how i actually switch to ortho, unless it can be easily posted up here (if it was just a couple of functions or commands that is).

Thanks alot and everyone who posted here rating++
-=pheonix2468=-

because i thought id have a gander at it. if you look at the includes it actually uses normal glut. But i used it in the beggining just to get something simple set up quick and i then just changed the includes for some reason.

well anyway ive just got back from the dentist, and have biology in 6 mins, good thing i live across the road from the school, hehehe. ill probably be on later.

This topic is closed to new replies.

Advertisement