Archive Pages Design$type=blogging

OpenGL Glut Create Menu Example

OpenGL Glut program can be mainly divided into 4 Parts. First part includes initialization with library and necessary files. Second Part in...

OpenGL Glut program can be mainly divided into 4 Parts. First part includes initialization with library and necessary files. Second Part include other necessary functions and third is the display functions which draw the object on screen. Final part is the main function. In this OpenGL Glut Create Menu Example, we will see these 4 parts separately.

This program will teach us how to add menu and submenu in opengl program. The menu can be created with click of right mouse button. In the OpenGL Glut Create Menu Example program menu and submenu in opengl id demonstration. The menu create have different types of structures whose color can be changed with selection of color in respective submenu.




FUNCTION USED

In this program we have three function - main, display, menu and createmenu used. We all know what main function do, so no tension about it. The function - display, menu and createmenu need to be understand.

The display function have all the code abou the objects that is going to show on the screen. The various object drawn are - Teaport, Torus, Sphere and Cone. Each of these objects are coded separately and placed in the display function. A global variable declared which helps in determination color and the object combination. Hence we are able to screen the objects in different colors as per the user selection in submenu. All these has been done with nested if else statement.

The createmenu Function lets us create menu and submenu. In main function first createmenu() is called. In the createmenu function glutCreateMenu(menu) is called for creation of each of the menu. Each selected menu entry passes the value passed for the callback.

Next is to add menu.The glutAddMenuEntry() function  will add the menu which passed to createmenu() along with the name of menu. For each menu a separate glutAddMenuEntry() function is required along with the different integer callback. If name of menu is same there will be now error while if integer callback is same, compiler error will show up.

Then we have glutAddSubMenu() function which create the submenu inside a menu item. It works in same way as glutAddMenuEntry() function. Different color is set in each of menu as submenu so that object in different color can be displayed.

OBJECTS USED IN THE PROGRAM

These are following functions used in the program along with the opengl functions.

  1. Teapot - glutSolidTeapot(r);
  2. Sphere - glutWireSphere(r, w, h);
  3. Torus - glutWireTorus(r, f, w, h);
  4. Cone - glutWireCone(r, f, w, h);
The color of each object used - Red,White,Yellow. Green and Blue attached with the menu in this OpenGL Glut Create Menu Example. Hence there are 5*4=20 objects can be drawn in display.

To trigger the menu and popup the menu, it can be attached to right or left mouse button with glutAttachMenu(). 

To attach it to right mouse button  - glutAttachMenu(GLUT_RIGHT_BUTTON);
To attach it to left mouse button - glutAttachMenu(GLUT_LEFT_BUTTON);


In our program we have used the GLUT_RIGHT_BUTTON so menu will appear on right click of mouse.

Download the source code.

COMMENTS

Name

3D Bi-Cycle 3D Game 3D Laptop 3D Objects 3D Projects 3D Zoo Algorithm Android Aquarium Bellman-Ford Algorithm B├ęzier curves Block Breaker Blockshooting Bucket Sort C# Chess Clock Code Blocks Colors Complex Project Complex Projects Crab Pong Cross Zero Doll DSAV Escapa Fighter Jet First Come First Serve Flag Flag Hoisting Fluids Font Demo Games Gear Motion GlutDino Glutplane Graphics Editor iOS iPhone Java Java OpenGL Graphics Programming Light Torus Linked List Ludo Board Game Mancala board games Memory blocks game Memory Game Menu Mickey Mouse Minesweeper Miniature Steam Engine moth Motion Blur MoveLight moving car Moving Ship Multiplex Networking Based Project Nuclear Power Plant Olympic opengl c++ examples OpenGL ES OpenGL Programming OpenGL Tutorial Origami OS Based Projects Paint Paper Folding Particles Drop Path Finding ping pong Pong Game Project Report Projects Report Puzzles qix like Queuqe Random Flowing lines Ray Rigid Body Rings Robot sample c++ opengl code Screen Saver Screen Saver Ship Shadow Cube Shadowfun Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Sphere Spot Light Swing Stack Stars Taj Mahal The Edge Game Tic Tac Toe Tower of Hanoi Traffic Signal Transformation Triangular Animation Trippy Tutorial water ripple effects Whirlpool
false
ltr
item
OpenGL Projects: OpenGL Glut Create Menu Example
OpenGL Glut Create Menu Example
https://2.bp.blogspot.com/-xI3M2ZyQih0/WFGTeLDaAuI/AAAAAAAAIJk/WXyMs3hUD681GyQDJf25qMQGoPEkV03LgCLcB/s320/OpenGL%2BGlut%2BCreate%2BMenu%2BExample.png
https://2.bp.blogspot.com/-xI3M2ZyQih0/WFGTeLDaAuI/AAAAAAAAIJk/WXyMs3hUD681GyQDJf25qMQGoPEkV03LgCLcB/s72-c/OpenGL%2BGlut%2BCreate%2BMenu%2BExample.png
OpenGL Projects
http://www.openglprojects.in/2016/12/opengl-glut-create-menu-example.html
http://www.openglprojects.in/
http://www.openglprojects.in/
http://www.openglprojects.in/2016/12/opengl-glut-create-menu-example.html
true
2020194800836807725
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago