Main
janelaMain=glutCreateWindow("OpenGL");
glutReshapeFunc(myReshapeMain);
glutDisplayFunc(displayMain);
glutKeyboardFunc(keyboard);
glutTimerFunc(30, Timer, 0);
glutSpecialFunc(special);
glutSpecialUpFunc(specialUp);
myInit();
janela1=glutCreateSubWindow(janelaMain,10,10,10,10);// dentro do Reshape da main os valores são alterados
glutReshapeFunc(myReshapeJanela1);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutSpecialUpFunc(specialUp);
myInit();
janela2=glutCreateSubWindow(janelaMain,300,20,30,30);// dentro do Reshape da main os valores são alterados
glutReshapeFunc(myReshapeJanela2);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutSpecialUpFunc(specialUp);
myInit();
glutMainLoop();
Reshapes
#define GAP 40
void myReshapeMain(int w, int h)
{
GLint tamJan,altJan;
tamJan=(w-3*GAP)/2;
altJan=h-2*GAP;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,w,h,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutSetWindow(janela1);
glutPositionWindow(GAP,GAP);
glutReshapeWindow(tamJan,altJan);
glutSetWindow(janela2);
glutPositionWindow(GAP+tamJan+GAP,GAP);
glutReshapeWindow(tamJan,altJan);
}
void myReshapeJanela1(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w/h, 1,100);
gluLookAt(0,30,30, 0,0,0, 0,0,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void myReshapeJanela2(int w, int h)
{
escala=5;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(-10.0 * (GLfloat) escala, 10.0 * (GLfloat) escala, -10.0 * (GLfloat) escala* (GLfloat) h / (GLfloat) w,
10.0 * (GLfloat) escala* (GLfloat) h / (GLfloat) w, -50.0, 50.0);
else
glOrtho(-10.0 * (GLfloat) escala * (GLfloat) w / (GLfloat) h,
10.0 * (GLfloat) escala * (GLfloat) w / (GLfloat) h, -10.0 * (GLfloat) escala, 10.0 * (GLfloat) escala, -50.0, 50.0);
glRotatef(45,-1,0,0);
glRotatef(45,0,0,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
Redisplay All
void RedisplayAll()
{
glutSetWindow(janelaMain);
glutPostRedisplay();
glutSetWindow(janela1);
glutPostRedisplay();
glutSetWindow(janela2);
glutPostRedisplay();
}
Strings
/* font pode ser
GLUT_BITMAP_8_BY_13
GLUT_BITMAP_9_BY_15
GLUT_BITMAP_TIMES_ROMAN_10
GLUT_BITMAP_TIMES_ROMAN_24
GLUT_BITMAP_HELVETICA_10
GLUT_BITMAP_HELVETICA_12
GLUT_BITMAP_HELVETICA_18
*/
void drawstr(GLfloat x, GLfloat y, void *font, char* format, ...)
{
va_list args;
char buffer[255], *s;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
glRasterPos2f(x, y);
for (s = buffer; *s; s++)
glutBitmapCharacter(font, *s);
}
/* font pode ser
GLUT_STROKE_ROMAN
GLUT_STROKE_MONO_ROMAN
*/
void drawstroke(GLfloat x, GLfloat y, GLfloat z, void *font, char* format, ...)
{
va_list args;
char buffer[255], *s;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
glTranslatef(x, y, z);
for (s = buffer; *s; s++)
glutStrokeCharacter(font, *s);
}
Exemplo de desenho de strings
drawstr(5,10, GLUT_BITMAP_8_BY_13,"Texto Bitmap");
glPushMatrix();
glScalef(0.3,-0.3,0.3);
drawstroke(505,-100, 0, GLUT_STROKE_ROMAN,"Texto Stroke");
glPopMatrix();