Original Post
I''m trying to make a simple tiled 3d app, but have run into a few problems that I can''t figure out. Perhaps someone here can help me.
The first problem I''m having is that creating a second subwindow using GLUT isn''t working. It works fine if I comment out the second offending window, but uncommenting it messes everything up. Basically, I want the top/main window to show my view, and the bottom part to be a status bar. The bottom part is supposed to take up the full width is the screen, but only the bottom 100 pixels.
The second problem is the game key situtation. I tried making the code exactly like the 3D tech tutorial, but just resulted in no keys working. Can''t figure out what the tutorial is doing differently.
Also, how do I get rid of the annoying breakpoint messages when I exit out of the debugger?
Anyways, here is my main.cpp code is below, and the full source is available here
#include "main.h"
#include "draw.h"
#include "tile.h"
#define cint const int
static float angle=0.0,ratio;
static float x=50.0f,y=50.0f,z=150.0f; // camera position
static float lx=0.0f,ly=0.1f,lz=-1.0f; // line of sight
cint RIGHT = 1;
cint LEFT = 2;
cint UP = 3;
cint DOWN = 4;
int W = 600;
int H = 600;
int mainWindow, subWindow1;
void changeSize2(int w, int h)
{
glutSetWindow(subWindow1);
if(h == 0)
h = 1;
ratio = 1.0f * w / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(x, y, z,
x + lx,y + ly,z + lz,
0.0f,1.0f,0.0f);
}
void changeSize(int w,int h)
{
if(h == 0)
h = 1;
W = w;
H = h;
glutSetWindow(subWindow1);
glutPositionWindow(0,0);
glutReshapeWindow(W, H-101);
changeSize2(W, H);
/*
glutSetWindow(subWindow2);
glutPositionWindow(W,H-100);
glutReshapeWindow(W, 100);
*/
}
void initScene()
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glClearDepth(1.0f);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
LoadGLTextures();
}
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
draw();
glutSwapBuffers();
}
void renderSceneAll(void)
{
renderScene();
}
void renderScene2(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void processNormalKeys(unsigned char key, int x, int y) {
if (key == 27)
exit(0);
}
void inputKey(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_LEFT:
move(RIGHT);
break;
case GLUT_KEY_RIGHT:
move(LEFT);
break;
case GLUT_KEY_UP:
move(UP);
break;
case GLUT_KEY_DOWN:
move(DOWN);
break;
}
}
void move(int d)
{
switch (d)
{
case 1:
x+=1;
break;
case 2:
x-=1;
break;
case 3:
y-=1;
break;
case 4:
y+=1;
break;
}
glLoadIdentity();
gluLookAt(x, y, z,
x + lx,y + ly,z + lz,
0.0f,1.0f,0.0f);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(W,H);
mainWindow = glutCreateWindow("Test");
glutIgnoreKeyRepeat(1);
glutKeyboardFunc(processNormalKeys);
glutReshapeFunc(changeSize);
glutDisplayFunc(renderSceneAll);
glutIdleFunc(renderSceneAll);
initScene();
subWindow1 = glutCreateSubWindow(mainWindow, 0,0, W, H-100);
glutDisplayFunc(renderScene);
initScene();
/* subWindow2 = glutCreateSubWindow(mainWindow, 0, H-100, W, 100);
glutDisplayFunc(renderScene2);
initScene();
*/
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(inputKey);
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutReshapeFunc(changeSize);
glutMainLoop();
return(0);
}
|