Hi to all
I am student in university of ioannina and i have a project in OpenGL.
I have to create a game like tetris and i diceded to make it with subwindows.
I create subwindows succesfully and i can print a text in subwindows method(glutDisplayFunc()) succesfully, but when i try to print a text outside of subwindows method its IMPOSSIBLE!!!!! TAKE A LOOK AT THE TEXT IN MAIN AND THE OTHER TEXT!!!!!!
Can someone help me???
Here is my code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <sstream>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#define WIDTH 302
#define HEIGHT 522
using namespace std;
int mainWin, subWin1, subWin2;
void processKeyboardKeys(unsigned char key, int x, int y)
{
switch(key)
{
case 27:
glutSetWindow(mainWin);
exit(0);
break;
}
}
void printString(string s, int length, double x, double y, int subwintoprint)
{
glutSetWindow(subwintoprint);
glRasterPos2i(x,y);
for(int i=0; i<length; i++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, s[i]);
}
glFlush();
}
void mainDisplay(void)
{
glutSetWindow(mainWin);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(0, 61);
glVertex2f(WIDTH, 61);
glVertex2f(0, 62);
glVertex2f(WIDTH, 62);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2f(WIDTH-61, 63);
glVertex2f(WIDTH-61, HEIGHT);
glVertex2f(WIDTH-60, 63);
glVertex2f(WIDTH-60, HEIGHT);
glEnd();
string score = "mainWin";
glColor3f(1.0, 1.0, 1.0);
printString(score.data(), score.size(), 40, 250, mainWin);
glutKeyboardFunc(processKeyboardKeys);
glFlush();
}
void subWin1Display(void)
{
glutSetWindow(subWin1);
glClearColor(0.0, 0.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluOrtho2D(0, WIDTH, 0, 60);
string score = "subWin1";
glColor3f(1.0, 1.0, 1.0);
printString(score.data(), score.size(), 40, 25, subWin1);
glFlush();
}
void subWin2Display(void)
{
glutSetWindow(subWin2);
glClearColor(0.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluOrtho2D(0, 60, 0, HEIGHT-62);
string f = "sub";
glColor3f(0.0, 0.0, 0.0);
printString(f.data(), f.size(), 0, 200, subWin2);
string g = "Win2";
glColor3f(0.0, 0.0, 0.0);
printString(g.data(), g.size(), 0, 180, subWin2);
glFlush();
}
void SubWindows(void)
{
subWin1 = glutCreateSubWindow(mainWin, 0, HEIGHT-60, WIDTH, 60);
glutDisplayFunc(subWin1Display);
subWin2 = glutCreateSubWindow(mainWin, WIDTH-60, 0, 60, (HEIGHT-63));
glutDisplayFunc(subWin2Display);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (300, 300);
glutInitWindowSize (WIDTH, HEIGHT);
mainWin = glutCreateWindow ("BRAXAPSA");
gluOrtho2D(0, WIDTH, 0, HEIGHT);
glutDisplayFunc(mainDisplay);
SubWindows();
string g = "HELP ME!!!";
glColor3f(1.0, 1.0, 1.0);
printString(g.data(), g.size(), 0, 180, mainWin);
glutMainLoop();
return 0;
}