Results 1 to 2 of 2

Thread: can't figure out how to display the scence

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    pakistan
    Posts
    6

    can't figure out how to display the scence

    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)MapDa ta[i][j]/10000);
    glVertex3f((GLushort)i,(GLushort)j+1,(GLushort)Map Data[i][j+1]/10000);
    glVertex3f((GLushort)i+1,(GLushort)j+1,(GLushort)M apData[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\n");

    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 \n", 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("\n");
    }

    }
    int main (int argc, char * argv[])
    {
    char fileName[256];
    int i;

    // Show the command line
    printf("Command line:\n");
    for (i = 0; i < argc; i++)
    printf("argv[%d] = --%s--\n", 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\n");
    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;
    }


    //---------------------------------------------------------------------------

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: can't figure out how to display the scence

    Hi !

    Try without the glRotate and glScale and see if you can get that working first, the code look's ok to me after a quick look, try something easy like:

    gluLookAt( 0,0,-100, 0,0,0, 0,1,0)

    And see if you can get that working, also make sure that you render your own stuff so that it is visible with that camera (close to origin 0,0,0)

    Mikael

Similar Threads

  1. Trying to figure our glOrtho
    By tr1234586 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-14-2010, 10:43 PM
  2. Who can help me figure this our? thx
    By koalacui in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-04-2005, 07:56 PM
  3. using more than one figure
    By Ziggurat in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-27-2002, 12:35 AM
  4. stick man figure
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-23-2001, 08:38 AM
  5. human figure
    By yaksha in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 07-09-2000, 04:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean