Escolar Documentos
Profissional Documentos
Cultura Documentos
27.. BIBLIOGRAPHY26 .. CONCLUSION23-25 .. SOUTPUT17-22 DETAILED DESIGN16 . REQUIREMENT SPECIFICATION 9-15. FUNCTIONS USED7-8 ....... .............INTRODUCTION TO OPENGLPAGE NO CONTENTS
Fonts are written in a GLUT bitmap font. The font display is positioned in pixels with upper-left origin. With the help mouse an interaction with output using menus and submenus is done. Many more GLUT functions have been used and its working is showed in this. The aim in developing this project is to illustrate the applications of Bitmap Font in OpenGL. The project mainly focuses on how to use the BITMAP FONTS using GLUT function in OpenGL Environment. And hence many operations like increasing font size, changing fonts and changing colors are included in this. Cursor Image changing facility using menus and submenus has been implemented in this project for increasing interaction. BSTRACT A
2
We also extend our sincere thanks to the non-teaching staff and all the friends for their co-operations. of CSE Dept for reviewing the project and for their constant support advice and encouragement. our staff member lecturer CSE Dept, and all the lecturersWe are extremely thankful to. For his valuable suggestions and guidance in the implementation of this project.
Mr.C.K.SRINIVASWe also express our sincere thanks to Computer Science Department for his inspiration and constant support in the development of the project. Prof C.N.SHARIFFWe express our sincere thanks to our
beloved H.O.D for providing all the required facilities for my mini-project Dr. U. ERANNAPrincipal thank our required facilities for my mini-project Mr.PRITHVIRAJ.Y.Jthank our Deputy Director Weof BITM Wefor providing all the
for his co-operation during the course of this project. Dr.YASHWANT BHUPALDirector We are highly grateful to Though the benefit achieved from them can be adequately thanked. We would like to express our heartfull gratitude towards them. .The completion of our mini project successfully was possible only because of the people who guided us and encouraged usACKNOWLEDGEMENT
CHAPTER 1 INTRODUCTION
1.1 Introduction to the OpenGL
OpenGL is an application program interface that is used to define 2D and
3D computer graphics.OpenGL has become the industry's most widely used and supported 2D and 3D graphics application programming interface (API), bringing thousands of applications to a wide variety of computer platforms. OpenGL fosters innovation and speeds application development by incorporating a broad set of rendering, texture mapping, special effects, and other powerful visualization functions. Developers can leverage the power of OpenGL across all popular desktop and workstation platforms, ensuring wide application deployment. OpenGL is independent of the hardware, operating, and windowing systems in use. The fact that it is windowing-system independent, makes it portable. OpenGL program must interface with the windowing system of the platform where the graphics are to be displayed. Therefore, a number of windowing toolkits have been developed for use with OpenGL. OpenGL functions are designed to provide 2D and 3D graphics with the emphasis on 3D. The program is fully functional, including everything that users usually want out of 3D graphics. This includes: 3D modeling transformations color lighting
OpenGL functions in a client/server environment. That is, the application program producing nthe graphics may run on a machine other than the one on which the graphics are displayed. The server part of OpenGL, which runs on the workstation where the graphics are displayed, can access whatever physical graphics device or frame buffer is available on that machine. OpenGL is designed as a streamlined, hardware-independent interface to be implemented on many different hardware platforms. To achieve these qualities, no commands for performing
6
windowing tasks or obtaining user input are included in OpenGL; instead, you must work through whatever windowing system controls the particular hardware you're using. Similarly, OpenGL doesn't provide high-level commands for describing models of threedimensional objects. Such commands might allow you to specify relatively complicated shapes such as automobiles, parts of the body, airplanes, or molecules.
Multiplewindows for OpenGL rendering. Callback driven event processing. Sophisticated input devices. An idle routine and timers. A simple, cascading pop-up menu facility. Utility routines to generate various solid and wire frame objects. Support for bitmap and stroke fonts.I Miscellaneous window management functions, including managing overlays.
GLUT is the OpenGL Utility Toolkit. GLUT is used in the development of OpenGL applications. OpenGL is a graphics library which means that it can do all sorts of things with geometric forms, lightings, transformations etc. But OpenGL was designed to be portable so it can be used within various environments / operating systems (Linux, Unix, Solaris, Windows, Amiga,...) without changing the OpenGL code. Within the OpenGL programming Guide (ISBN 0-201-60458-2, also known as " the red book ") one says the following about this subject: The OpenGL Utility Toolkit (GLUT) is a windowsystem-independent toolkit written by Mark Kilgard, to hide the complexities of differing window system APIs. So basically GLUT provides you with a utility that creates a window for you, in that window you can show the output of your OpenGL program. But glut is replacable,
7
you can use the GtkGLArea or GtkGLExt for GTK, you can also use OpenGL within Perl without explicitly using GLUT.
1. display() 2. reshape() 3. selectFont(int newfont) 4. selectMessage(int msg) 5. selectCursorImage(int msg) 6. selectColor(int color) 7. output(int x, int y, char *string) 8. spin()
#include<GL/glut.h> Includes the OpenGL utility Toolkit header file. This statement automatically includes gl.h, glu.h, glx.h. And with Microsoft Windows, it includes the appropriate header file to access WGL.
glutInitWindowPosition(int x, int y) specifies the screen location for the upper-left corner of your window. glutCreateWindow(char *name) creates a top-level window. The name will be provided to the window system as the window's name. The intent is that the window system will label the window with the name. Implicitly, the current window is set to the newly created window. Each created window has a unique associated OpenGL context. State changes to a window's associated OpenGL context can be done immediately after the window is created.
implementation dependent. The intent is for the image to convey the meaning of the cursor name. For a top-levelwindow, GLUT CURSOR INHERIT uses the default window system cursor
glutReshapeFunc(void (*func)(int width, int height)) sets the reshape callback for the current window. The reshape callback is triggered when a window is reshaped. A reshape callback is also triggered immediately before a window's first display callback after a window is created or whenever an overlay for the window is established. The width and height parameters of the callback specify the new window size in pixels. Before the callback, the current window is set to the window that has been reshaped.
Display Callback void display(void) { glClear(GL_COLOR_BUFFER_BIT); output(100, 54, "This is written in a GLUT bitmap font."); output(90, 400, "(positioned in pixels with upper-left origin)"); glPushMatrix(); glTranslatef(1,1,1); glRotatef(theta,0,0,0); output(400, 54, "This is written in a GLUT bitmap font."); output(390, 400, "(positioned in pixels with upper-left origin)"); output(500, 250, message); glPopMatrix(); glutSwapBuffers(); }
13
The interface for the openGL requires for the user to have a mouse connected, and the corresponding drivers installed. This is because most of the implementation details require and presume the presence of a mouse.
3.4 Hardware Interface:The standard output device, as mentioned earlier has been assumed
to be a color monitor. The mouse, the main input device, has to be functional. Apart from these hardware requirements, there should be sufficient hard disk space and primary memory available for proper working of the package.
3.6 FEATURES
Mouse interaction in generating Menus and submenus. GLUT font rendering function have been used. GLUT Cursor Image Functions have been used. Use of GLUT Window Management Functions. Use of GLUT Menu Management Functions.
15
First it initializes a default font by using a for loop at the starting of the display function. Then as going on a sequence of submenus in main menu are created by assigning the respective call back functions to them. Call Back Functions Are SELECT COLOR SELECT FONT SELECT MESSAGE SELECT CURSOR
And finally these submenus are attached to the main menu in appropriate way. Actually all these functions and activates are done in the reverse way as execution starts.
DISPLAY FUNCTION: This function is responsible for the displaying the BITMAP FONT on the window with starting pixel position at origin. The parameters are sent from the display function to the output function (parameters are font and message string).
16
And also rotation and translation attributes and actions are also included in the function. The display is like ZOOM IN and ZOOM OUT type which constantly goes on displaying in that fashion.
Mini project on Glut Bitmap Font using openGL if(newfont==7) { glutFullScreen(); } else if(newfont==8) { exit(0); } else { font = fonts[newfont]; glutPostRedisplay(); } } void selectMessage(int msg) { switch (msg) { case 1: message = "Welcome to Our Project"; break; case 2: message = "Our Project is on using BITMAP Text in Opengl"; break; case 3: message = "Thanks for visiting Our project Hope you like it!!!...."; break; } } void selectCursorImage(int msg) { switch (msg) { 18
Mini project on Glut Bitmap Font using openGL case 1: glutSetCursor(GLUT_CURSOR_HELP); break; case 2: glutSetCursor(GLUT_CURSOR_CYCLE); break; case 3: glutSetCursor(GLUT_CURSOR_WAIT); break; case 4: glutSetCursor(GLUT_CURSOR_CROSSHAIR); break; case 5: glutSetCursor(GLUT_CURSOR_NONE); break; case 6: glutSetCursor(GLUT_CURSOR_DESTROY); break; case 7: glutSetCursor(GLUT_CURSOR_SPRAY); break; } } void selectColor(int color) { switch (color) { case 1: glColor3f(0.0, 1.0, 0.0); break; case 2: glColor3f(1.0, 0.0, 0.0); break; case 3: glColor3f(1.0, 1.0, 1.0); 19
Mini project on Glut Bitmap Font using openGL break; case 4: glColor3f(0.0, 0.0, 1.0); break; } glutPostRedisplay(); } void tick(void) { glutPostRedisplay(); } void output(int x, int y, char *string) { int len, i; glRasterPos2f(x, y); len = (int) strlen(string); for (i = 0; i < len; i++) { glutBitmapCharacter(font, string[i]); } } GLfloat theta=0; void spin() { theta+=0.2; if(theta>360.0)theta-=360.0; glutPostRedisplay(); }
void 20
Mini project on Glut Bitmap Font using openGL display(void) { glClear(GL_COLOR_BUFFER_BIT); output(100, 54, "This is written in a GLUT bitmap font."); output(90, 400, "(positioned in pixels with upper-left origin)"); glPushMatrix(); glTranslatef(1,1,1); glRotatef(theta,0,0,0); output(400, 54, "This is written in a GLUT bitmap font."); output(390, 400, "(positioned in pixels with upper-left origin)"); output(500, 250, message); glPopMatrix(); glutSwapBuffers(); } void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //glFrustum(w, h,0, 0, 2, 10); gluOrtho2D(0,w,h,0); glMatrixMode(GL_MODELVIEW); gluLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0); } int main(int argc, char **argv) { int i, msg_submenu, color_submenu,cursor_submenu; glutInit(&argc, argv); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-mono")) { font = GLUT_BITMAP_9_BY_15; 21
Mini project on Glut Bitmap Font using openGL } } glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(600, 500); glutCreateWindow("GLUT bitmap font example"); glClearColor(0.0, 0.0, 0.0, 1.0); glutDisplayFunc(display); glutReshapeFunc(reshape); glutSetWindowTitle("Pranoy"); glutSetIconTitle("Pranoy"); glutIdleFunc(tick); glutIdleFunc(spin); msg_submenu = glutCreateMenu(selectMessage); glutAddMenuEntry("Welcome", 1); glutAddMenuEntry("Info", 2); glutAddMenuEntry("End", 3); cursor_submenu = glutCreateMenu(selectCursorImage); glutAddMenuEntry("Help", 1); glutAddMenuEntry("Cycle", 2); glutAddMenuEntry("Wait", 3); glutAddMenuEntry("Cross Hair", 4); glutAddMenuEntry("None", 5); glutAddMenuEntry("Destroy", 6); glutAddMenuEntry("Spray", 7); color_submenu = glutCreateMenu(selectColor); glutAddMenuEntry("Green", 1); glutAddMenuEntry("Red", 2); glutAddMenuEntry("White", 3); glutAddMenuEntry("Blue", 4); glutCreateMenu(selectFont); glutAddMenuEntry("9 by 15", 0); glutAddMenuEntry("Times Roman 10", 1); glutAddMenuEntry("Times Roman 24", 2); glutAddMenuEntry("Helvetica 10", 3); glutAddMenuEntry("Helvetica 12", 4); glutAddMenuEntry("Helvetica 18", 5); 22
Mini project on Glut Bitmap Font using openGL glutAddMenuEntry("8 BY 13", 6); glutAddMenuEntry("Full screen", 7); glutAddMenuEntry("Exit Full Screen", 8); glutAddSubMenu("Messages", msg_submenu); glutAddSubMenu("Color", color_submenu); glutAddSubMenu("Change Cursor Image", cursor_submenu); glutAttachMenu(GLUT_RIGHT_BUTTON); glutAttachMenu(GLUT_LEFT_BUTTON); glutAttachMenu(GLUT_MIDDLE_BUTTON); glutMainLoop(); return 0;
23
CHAPTER 5 OUTPUTS:
24
Fig(5.2): BITMAP FONT message changed and also color to red and moving towards corner.
25
26
center
CHAPTER 6 CONCLUSION
We acquired knowledge about terms, concepts and questions related to the subject what make us capable of working with the commands of the OpenGL language, GLUT LIBRARY FUNCTIONS and consequently we are prepared to elaborate 3D TEXT based graphical projects of the more diverse types. This project gave us a satisfactory view of Text mapping, text pixel positioning, text rotations and Font rendering operations.
27
CHAPTER7 BIBLIOGRAPHY
INTERACTIVE COMPUTER GRAPHICS-5th EDITION -EDWARD ANGEL www.opengl.org/documentation/books/ COMPUTER GRAPHICS USING OPENGL-2nd EDITION -F.S.HILL THE OPENGL UTILITY TOOLKIT (GLUT) PROGRAMMING INTERFACE.
28
29