banner



How To Draw String In Opengl

In the previous post, which highlights on making a front screen for the OpenGL mini projects a function chosen drawstring was shown but didn't explained well as information technology was causeless to be understood easily past the students but few of them demand it's code, which was not in that location. To help them out and sort the error they have,  hither I fabricated a simple tutorial to show, how we tin display a cord in the projects.

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

Get-go declared  a indentifire that will hold the current font type -

void *currentfont;

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

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

At present the most of import part, Lawmaking a function drawstring(), it should incorporate 4 arguments - x, y, z coordinates and a cord. While the coordinate assumed to be the space where string to be placed and the string is the value to exist display.  Code is beneath -

void drawstring(float ten,float y,float z,char *string)
{
char *c;
glRasterPos3f(x,y,z);
for(c=string;*c!='\0';c++)
{ glColor3f(0.0,0.0,0.0);
glutBitmapCharacter(currentfont,*c);
}
}

At present everything has been washed. Let display something in our program. Let started with v simple sentence. Y'all can display whatsoever simply I have code like below -

void text(void)
{
setFont(GLUT_BITMAP_HELVETICA_18);
glColor3f(0.0,1.0,1.0);
drawstring(150.0,455.0,1.0,"* * * * * * * * * * THE DRAWSTRING Part DEMO * * * * * * * * * *");

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

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

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

setFont(GLUT_BITMAP_8_BY_13);
glColor3f(1.0,1.0,one.0);
drawstring(220.0,240.0,1.0,"I am GLUT_BITMAP_8_BY_13 in white");

setFont(GLUT_BITMAP_9_BY_15);
glColor3f(1.0,0.0,1.0);
drawstring(220.0,185.0,1.0,"I am GLUT_BITMAP_9_BY_15 in pinkish");
glFlush();

}

Below is the Whole Program -

Source: https://www.openglprojects.in/2012/04/tutorial-how-to-display-strings-in.html

Posted by: hawkinsgail2001.blogspot.com

0 Response to "How To Draw String In Opengl"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel