Ok, this may be a silly question but its driving me nuts. I have a terrain editor that basically draws land within a box. The size of the box is determined by the map scale and the number of points in the terrain grid, for example map scale of 100 and a grid of 512x512 would create a square from coordinates (0,0) to (51200,-51200) in the XZ plane. I then set the camera at one end of the square overlooking the terrain.
This works fine, but when I change the number of points in the grid or the map scale the image doesn’t get any bigger in my viewport. I can set the scale to 1 or 1000000 but the square never appears any bigger. I know that the coordinate scale on the screen is changing because hills of the same height are mountains at scale 1 but flat at 1000000, plus the camera which moves a fixed number of units per second goes twice as slow when doubling the scale and twice as fast when halving the scale. So basically the program is resizing the coordinate system so that this box always fits on the screen no matter what the X and Z coordinates are.
What part of the code determines the coordinate scale as it is drawn on the screen? I’m not talking about using scaling transformations while the program is running. Basically I just want the terrain to appear twice as large on the screen if I double the scale pre-compile. Here are snippets of my code, I’ve taken out the parts that I don’t think are relavent. Thanks for any help!
void Initialize() {
glClearColor(0.0f,0.0f,0.0f,0.0f); // clear to black
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
// initialize the terrain data and load the texture
InitializeTerrain();
LoadTextures();
}
case WM_CREATE:
hDC = GetDC(hwnd); // get device context for window
g_HDC = hDC;
SetupPixelFormat(hDC); // call your pixel format setup
hRC = wglCreateContext(hDC); // create rendering context
wglMakeCurrent(hDC, hRC); // make rendering context current
return 0;
break;
case WM_SIZE:
height = HIWORD(lParam);
width = LOWORD(lParam);
if (height == 0) { // to avoid division by zero errors
height = 1;
}
// reset viewport to new dimensions
glViewport(0,0,width, height);
glMatrixMode(GL_PROJECTION); // set projection matrix
glLoadIdentity(); // reset projection matrix
// calculate aspect ratio of window
gluPerspective(54.0,(GLfloat)width/(GLfloat)height,1.0f,10000000.0f);
gluLookAt(cameraX, cameraY, cameraZ, lookX, lookY, lookZ,0.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW); // set modelview matrix
glLoadIdentity(); // reset modelview matrix
return 0;
break;
void Render() {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glShadeModel(GL_SMOOTH);
// set the current texture to the land texture
glBindTexture(GL_TEXTURE_2D,land);
for (int index = 0; index<VERTEX_COUNT; index+=10) {
glDrawElements(GL_TRIANGLE_FAN,10,GL_UNSIGNED_INT,&g_indexArray[index]);
}
// enable blending
glEnable(GL_BLEND);
// enable read only depth buffer
glDepthMask(GL_FALSE);
// set the blend function to transparency
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
// DRAW WATER HERE
// set back to normal depth buffer mode
glDepthMask(GL_TRUE);
// disable blending
glDisable(GL_BLEND);
glFlush();
SwapBuffers(g_HDC);
}