hi,
well i’m making a height field and i finally got it working…but now i’ve got this problem…i am not able to adjust the glulookat(…) here’s the code can someone tell me wat values should i use to get this working
////////////////////////////my code///////
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <windows.h>
#include <math.h>
#include <stdlib.h>
#include <math.h>
#include “utility.h”
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#pragma argsused
#define Width 150
#define Depth 100
/* Bytes per data value */
#define ByteSize 1
typedef short MapValue;
/* Dynamically allocated array to hold data, single array,
OR, Dynamically allocated array, 2D form. Pick one. */
MapValue ** MapData;
//#define Near 0.5
//#define Far 2000.0
#define Far 2000.0
#define Near 2.0
#define cmdNoCull 1
#define cmdCWFront 2
#define cmdCCWFront 3
#define cmdExit 99
static int AppMenu;
static GLfloat Spin;
static void drawCube()
{
int i;
for(i=0;i<90;i++)
{
for(int j=0;j<90;j++)
{
glBegin(GL_TRIANGLE_STRIP);
glVertex3f((GLushort)i,(GLushort)j,(GLushort)MapData[i][j]/10000);
glVertex3f((GLushort)i,(GLushort)j+1,(GLushort)MapData[i][j+1]/10000);
glVertex3f((GLushort)i+1,(GLushort)j+1,(GLushort)MapData[i+1][j+1]/10000);
glEnd();
}
}
}
static void display ()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
/*gluLookAt(-100.0,-50.0,-200.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);*/
gluLookAt(-100.0, 0, -200.0,
0.0, 0.0, 0.0,
0.0, 1.0, -1.0);
/*gluLookAt(-100.0,-2,-200,
0.0, -1.0, 20,
0.0,1.0,-1);*/
glRotatef(Spin, 0.0, 1.0, 0.0);
glScalef(2, 2, 2);
glColor3f(0.0, 1.0, 0.0);
glPushMatrix();
glTranslatef(5.0,-10.0,-25.0);
drawCube();
glPopMatrix();
//CheckGL();
glutSwapBuffers();
}
/static void spinDisplay (void)
{
Spin += 2.0;
if (Spin > 360.0)
Spin -= 360.0;
glutPostRedisplay();
}/
static void menuChoice (int item)
{
switch (item) {
case cmdNoCull:
glDisable(GL_CULL_FACE);
break;
case cmdCWFront:
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CW);
break;
case cmdCCWFront:
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
break;
case cmdExit:
exit(0);
break;
default:
break;
}
}
static void initGraphics (void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
Spin = 0.0;
AppMenu = glutCreateMenu(menuChoice);
glutSetMenu(AppMenu);
glutAddMenuEntry("No cull", cmdNoCull);
glutAddMenuEntry("CW faces", cmdCWFront);
glutAddMenuEntry("CCW faces", cmdCCWFront);
glutAddMenuEntry("----", 0);
glutAddMenuEntry("Exit", cmdExit);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
static void resize (int width, int height)
{
GLfloat aspect;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
aspect = (float)width / (float)height;
gluPerspective(60.0, aspect, Near, Far);
glViewport(0, 0, width, height);
glMatrixMode(GL_MODELVIEW);
}
static void asciiKey (unsigned char key, int x, int y)
{
if (key == 27) /* ESC */
exit(0);
}
static void readMap2D (char * inputName)
{
FILE * input;
int i, j;
char msg[256];
/* Allocate, this time as array of arrays */
MapData = (MapValue**) malloc(Depth * sizeof(MapValue *));
for (i = 0; i < Depth; i++)
MapData[i] = (MapValue*) malloc(Width * sizeof(MapValue));
input = fopen(inputName, "rb");
if (input == NULL) printf("Cannot open map
");
for (i = 0; i < Depth; i++)
if (fread(MapData[i], ByteSize, Width, input) != Width) {
sprintf(msg, "Cannot read correct number of values for row %d
", i);
printf(msg);
}
fclose(input);
/* Print out, this time with two indexes */
for (i = 0; i < Depth; i++)
{
printf("Row %d: ", i);
/* Only print first and last four */
for (j = 0; j < 4; j++)
{
printf("%4d ", MapData[i][j]);
}
printf("... ");
for (j = Width - 4; j < Width; j++)
{
printf("%4d ", MapData[i][j]);
}
printf("
");
}
}
int main (int argc, char * argv[])
{
char fileName[256];
int i;
// Show the command line
printf("Command line:
");
for (i = 0; i < argc; i++)
printf("argv[%d] = --%s–
", i, argv[i]);
/*Here we copy one of the command line arguments into the file name */
if (argc > 1)
strcpy(fileName, argv[1]);
else {
printf("NO FILENAME
");
exit(1);
}
readMap2D(fileName);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 75);
glutCreateWindow("Surface");
initGraphics();
glutDisplayFunc(display);
glutReshapeFunc(resize);
//glutIdleFunc(spinDisplay);
glutKeyboardFunc(asciiKey);
glutMainLoop();
return 0;
}
//---------------------------------------------------------------------------