Archive Pages Design$type=blogging

Tutorial How to display strings in OpenGL mini projects

In the previous post, which highlights on making a front screen for the OpenGL mini projects a function called drawstring was shown but did...

In the previous post, which highlights on making a front screen for the OpenGL mini projects a function called drawstring was shown but didn't explained well as it was assumed to be understood easily by the students but few of them demand it's code, which was not there. To help them out and sort the error they have,  here I made a simple tutorial to show, how we can display a string in the projects.

To display strings in the project we can make function in different ways, call the defined front in OpenGL API. How to code is depend on the coder, what he want to do with the string and how he want to display it. Matter of fact is that the necessary things is to make sure once a function is made it must be flexible enough that Front sizes and the colours can be changed easily when ever needed, wherever needed. Keeping in the mind that A simple function is code, of which stepwise process is defined below. You can also see the different fonts demo.

First declared  a indentifire that will hold the current font type -

void *currentfont;

After the declaration of this, we define a function which will change the fonts or say set the font which we can to to display with the strings. Code for this is easy, just make a function called setFont(), code given below -

void setFont(void *font)
currentfont=font;                      // Set the currentfont to the font

Now the most important part, Code a function drawstring(), it should contain four arguments - x, y, z coordinates and a string. While the coordinate assumed to be the space where string to be placed and the string is the value to be display.  Code is below -

void drawstring(float x,float y,float z,char *string)
char *c;
{ glColor3f(0.0,0.0,0.0);

Now everything has been done. Let display something in our program. Let started with five simple sentence. You can display whatever but I have code like below -

void text(void)
drawstring(150.0,455.0,1.0,"* * * * * * * * * * THE DRAWSTRING FUNCTION DEMO * * * * * * * * * *");

glColor3f(0.0,0.0,1.0); // RGB color R=0 ; G=0 ; B =1; so blue!
drawstring(220.0,405.0,1.0,"I am GLUT_BITMAP_HELVETICA_18 in blue");

setFont(GLUT_BITMAP_HELVETICA_12); //Font set to helvetica with size 12
drawstring(220.0,350.0,1.0,"I am GLUT_BITMAP_HELVETICA_12 in red");

     drawstring(220.0,295.0,1.0,"I am GLUT_BITMAP_TIMES_ROMAN_24 in green");

drawstring(220.0,240.0,1.0,"I am GLUT_BITMAP_8_BY_13 in white");

drawstring(220.0,185.0,1.0,"I am GLUT_BITMAP_9_BY_15 in pink");


Below is the Whole Program -



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 flag of usa 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 Martyr’s Monument 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 Shaheed Minar Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Space Invaders 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
OpenGL Projects: Tutorial How to display strings in OpenGL mini projects
Tutorial How to display strings in OpenGL mini projects
OpenGL Projects
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