PDA

View Full Version : Starting...



hcrogma
04-17-2003, 08:19 AM
I got SDK from apple and load it on to my computer...I load the library to my project and choose the whole SDK as an access path....I followed the lesson 1 of NeHe tutorial and was able to load the window...I then went on the the next lesson.....and made the modifiction to drawscence but nothing show up into window...What I am I missing.....here is the main.c as it is writting in my project.

#include <iostream>
#include <stdio.h> // Header File For Standard Input / Output
#include <stdarg.h> // Header File For Variable Argument Routines
#include <string.h> // Header File For String Management
#include <stdlib.h>
#include <gl.h> // Header File For The OpenGL32 Library
#include <glu.h> // Header File For The GLu32 Library
#include <glut.h> // Header File For The GLUT Library
#include <math.h>

// Constants -----------------------------------------------------------------

#define kWindowWidth 400
#define kWindowHeight 300

// Function Prototypes -------------------------------------------------------

GLvoid InitGL(GLvoid);
GLvoid DrawGLScene(GLvoid);
GLvoid ReSizeGLScene(int Width, int Height);

// Main ----------------------------------------------------------------------

int main(int argc, char** argv)
{

glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (kWindowWidth, kWindowHeight);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);

InitGL();

glutDisplayFunc(DrawGLScene);
glutReshapeFunc(ReSizeGLScene);

glutMainLoop();

return 0;
}

// Init ----------------------------------------------------------------------

GLvoid InitGL(GLvoid)
{

glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading

glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Reset The Projection Matrix

gluPerspective(45.0f,(GLfloat)kWindowWidth/(GLfloat)kWindowHeight,0.1f,100.0f); // Calculate The Aspect Ratio Of The Window

glMatrixMode(GL_MODELVIEW);

}

// DrawGLScene ---------------------------------------------------------------
GLvoid DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View

glTranslatef(-1.5f,0.0f,-6.0f);

glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();

glTranslatef(3.0f,0.0f,0.0f);

glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();

glFlush();
}
/*GLvoid DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glFlush();
glutSwapBuffers();
}*/

// ReSizeGLScene ------------------------------------------------------------

GLvoid ReSizeGLScene(int Width, int Height)
{
glViewport (0, 0, (GLsizei) Width, (GLsizei) Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0, (GLfloat) Width / (GLfloat) Height, 0.1, 100.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

shinpaughp
04-17-2003, 08:44 AM
Because the z value of your glVertex calls are 0.0f. Try changing the z values to -1.0 or something between -0.1 and -100.0, or change gluPerspective to a call to glOrtho.

Bob
04-17-2003, 10:24 AM
He's translating the objects before drawing them, so the resulting Z is within the view frustum.

The problem is that you're missing an important thing in the display function. Compare your function with the one you commented out below and see what you're missing.

shinpaughp
04-17-2003, 10:48 AM
Bob, you are correct. (swap) I guess I didn't look as closely at the code as I thought. http://www.opengl.org/discussion_boards/ubb/redface.gif