PDA

View Full Version : Problem getting my model into skymap



nick2price
11-27-2008, 03:51 PM
I worked on to projects seperately. 1 creates a skymap and the other loads in and textures a 3ds max model car. I am having problems now getting my car into my skymap.
This is the code which loads in my car


#include "stdafx.h"
#include <windows.h>
#include <GL/glut.h>
#include "coursework2.h"
#include "texture.h"
#include "3dsloader.h"


// Absolute rotation values (0-359 degrees) and rotation increments for each frame
double rotation_x=0, rotation_x_increment=0.1;
double rotation_y=0, rotation_y_increment=0.05;
double rotation_z=0, rotation_z_increment=0.03;

// Flag for rendering as lines or filled polygons
int filling=1; //0=OFF 1=ON


obj_type object;



void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0); // This clear the background color to black
glShadeModel(GL_SMOOTH); // Type of shading for the polygons


// Projection transformation
glMatrixMode(GL_PROJECTION); // Specifies which matrix stack is the target for matrix operations
glLoadIdentity(); // initialize the projection matrix as identity
// gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,10.0f,10000.0f); // define the "viewing volume"

glEnable(GL_DEPTH_TEST); // enable the depth test (also called z buffer)
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); // Polygon rasterization mode (polygon filled)

glEnable(GL_TEXTURE_2D); // This Enable the Texture mapping

Load3DS (&amp;object,"GTR.3ds");

object.id_texture=LoadBitmap("body.bmp"); // The Function LoadBitmap() return the current texture ID


}



void display(void)
{
int l_index;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); // Modeling transformation
glLoadIdentity(); // Initialize the model matrix as identity

glTranslatef(0.0,0.0,-300); // move the object forward (the model matrix is multiplied by the translation matrix)

rotation_x = rotation_x + rotation_x_increment;
rotation_y = rotation_y + rotation_y_increment;
rotation_z = rotation_z + rotation_z_increment;

if (rotation_x > 359) rotation_x = 0;
if (rotation_y > 359) rotation_y = 0;
if (rotation_z > 359) rotation_z = 0;

glRotatef(rotation_x,1.0,0.0,0.0); // Rotations of the object (the model matrix is multiplied by the rotation matrices)
glRotatef(rotation_y,0.0,1.0,0.0);
glRotatef(rotation_z,0.0,0.0,1.0);

glBindTexture(GL_TEXTURE_2D, object.id_texture); // set the active texture

glBegin(GL_TRIANGLES);
for (l_index=0;l_index<object.polygons_qty;l_index++)
{
//----------------- FIRST VERTEX -----------------
// Texture coordinates of the first vertex
glTexCoord2f( object.mapcoord[ object.polygon[l_index].a ].u,
object.mapcoord[ object.polygon[l_index].a ].v);
// Coordinates of the first vertex
glVertex3f( object.vertex[ object.polygon[l_index].a ].x,
object.vertex[ object.polygon[l_index].a ].y,
object.vertex[ object.polygon[l_index].a ].z); //Vertex definition

//----------------- SECOND VERTEX -----------------
// Texture coordinates of the second vertex
glTexCoord2f( object.mapcoord[ object.polygon[l_index].b ].u,
object.mapcoord[ object.polygon[l_index].b ].v);
// Coordinates of the second vertex
glVertex3f( object.vertex[ object.polygon[l_index].b ].x,
object.vertex[ object.polygon[l_index].b ].y,
object.vertex[ object.polygon[l_index].b ].z);

//----------------- THIRD VERTEX -----------------
// Texture coordinates of the third vertex
glTexCoord2f( object.mapcoord[ object.polygon[l_index].c ].u,
object.mapcoord[ object.polygon[l_index].c ].v);
// Coordinates of the Third vertex
glVertex3f( object.vertex[ object.polygon[l_index].c ].x,
object.vertex[ object.polygon[l_index].c ].y,
object.vertex[ object.polygon[l_index].c ].z);
}
glEnd();

glFlush(); // This force the execution of OpenGL commands
glutSwapBuffers();
}


This code creates my skyboc


#include "stdafx.h"
#include <GL/glut.h>
#include <windows.h>
#include <stdio.h> //for file access
#include <gl\gl.h>
#include "skybox.h"
#include "glbmp.h"


bool skybox::LoadTexture(unsigned int & aTexture, const char * bitmap_file)
{
glbmp_t bitmap; //object to fill with data from glbmp


if(!glbmp_LoadBitmap(bitmap_file, 0, &amp;bitmap))
{
fprintf(stderr, "Error loading bitmap file: %s\n", bitmap_file);
}

//generate and bind the OpenGL texture
glGenTextures(1, &amp;aTexture);
glBindTexture(GL_TEXTURE_2D, aTexture);

//copy data from bitmap into texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.width, bitmap.height,
0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);

//set up texture filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

//free the bitmap
glbmp_FreeBitmap(&amp;bitmap);

return true;
}



void skybox::Init() {

OFFSET = 1/512.0; //set offset value for skybox

rot_x = 0.0; rot_y = 0.0;



LoadTexture(texture[0], "images/1.bmp");
LoadTexture(texture[1], "images/2.bmp");
LoadTexture(texture[2], "images/3.bmp");
LoadTexture(texture[3], "images/4.bmp");
LoadTexture(texture[4], "images/5.bmp");
LoadTexture(texture[5], "images/6.bmp");

}


//This is where the magic happens
void skybox::draw() {

glPushMatrix();
glRotated(rot_x, 1.0, 0.0, 0.0); //Rotate around the x axis
glRotated(rot_y, 0.0, 1.0, 0.0); //Rotate around the y axis

glColor3f(1.0f,1.0f,1.0f); //Set colour to White
glEnable(GL_TEXTURE_2D); //Enable texture mapping
glDisable (GL_DEPTH_TEST); //Disable depth testing

//before you can use a texture you have to bind it
glBindTexture(GL_TEXTURE_2D, texture[0 + text_offset]);

glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET,0.0 + OFFSET); glVertex3d (-10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET,0.0 + OFFSET); glVertex3d (-10.0,-10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET,1.0 - OFFSET); glVertex3d (-10.0,10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET,1.0 - OFFSET); glVertex3d (-10.0,10.0,10.0);

glEnd ();

glBindTexture(GL_TEXTURE_2D, texture[1 + text_offset]);
glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET,0.0 + OFFSET); glVertex3d (-10.0,-10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET,0.0 + OFFSET); glVertex3d (10.0,-10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET,1.0 - OFFSET); glVertex3d (10.0,10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET,1.0 - OFFSET); glVertex3d (-10.0,10.0,-10.0);
glEnd ();

glBindTexture(GL_TEXTURE_2D, texture[2 + text_offset]);
glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,0.0 + OFFSET); glVertex3d (10.0,-10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,0.0 + OFFSET); glVertex3d (10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,1.0 - OFFSET); glVertex3d (10.0,10.0,10.0);
glNormal3d (0.0,0.0,10.0); glTexCoord2d (0.0 + OFFSET ,1.0 - OFFSET); glVertex3d (10.0,10.0,-10.0);

glEnd ();

glBindTexture(GL_TEXTURE_2D, texture[3 + text_offset]);
glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,0.0 + OFFSET); glVertex3d (10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,0.0 + OFFSET); glVertex3d (-10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,1.0 - OFFSET); glVertex3d (-10.0,10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,1.0 - OFFSET); glVertex3d (10.0,10.0,10.0);

glEnd ();

glBindTexture(GL_TEXTURE_2D, texture[4 + text_offset]);
glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,0.0 + OFFSET); glVertex3d (-10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,0.0 + OFFSET); glVertex3d (10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,1.0 - OFFSET); glVertex3d (10.0,-10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,1.0 - OFFSET); glVertex3d (-10.0,-10.0,-10.0);

glEnd ();

glBindTexture(GL_TEXTURE_2D, texture[5 + text_offset]);
glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,0.0 + OFFSET); glVertex3d (-10.0,10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,0.0 + OFFSET); glVertex3d (10.0,10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,1.0 - OFFSET); glVertex3d (10.0,10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,1.0 - OFFSET); glVertex3d (-10.0,10.0,10.0);

glEnd ();

//Re-Enable the depth test
glEnable(GL_DEPTH_TEST);
//disable texture mapping
glDisable(GL_TEXTURE_2D);
glPopMatrix();


}




And this is my main class which at the moment loads in the skybox


#include "stdafx.h"
#include <GL/glut.h>
#include <windows.h>
#include <stdio.h> //for file access
#include <gl\gl.h>
#include "skybox.h"
#include "glbmp.h"
#include "coursework2.h"
#include "3dsloader.h"
#include "texture.h"

int screen_width=800;
int screen_height=600;

skybox aSkyBox;


GLvoid ReSizeGLScene(GLsizei width, GLsizei height) {

if (height<=0) { height=1; }

glViewport(0,0,width,height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int InitGL(GLvoid) {

glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH); //Try GL_FLAT to see the difference
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //Background colour
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST); //Enables depth testing
glDepthFunc(GL_LEQUAL); //Specifies how Depth testing is done
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Affects quality of colour and texture interpolation
glFrontFace (GL_CCW); //Specifies that the front of a face is defined
//in a Counter Clockwise manner
glCullFace(GL_BACK); //Specifies that the back of faces are not shown
//so OpenGL does not need to draw things twice
glEnable(GL_CULL_FACE); //Enables culling of faces


aSkyBox.Init(); //Initalize the Skybox


return TRUE;
}

void DrawGLScene(GLvoid) {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

aSkyBox.draw();
glutSwapBuffers();

}

int main(int argc, char **argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(screen_width,screen_height);
glutInitWindowPosition(0,0);
glutCreateWindow("Coursework 2");

glutReshapeFunc(ReSizeGLScene);
glutDisplayFunc(DrawGLScene);
InitGL();
glutMainLoop();

return(0);
}


In my main class, i tried adding somthing like
coursework2 aCoursework2, a bit like what i done for skymap. This didnt seem to work though. Is this the right approach to get my car into my skymap? And if it is, does it mean i would have to add a constructor to my coursework2.h file? At the moment my coursework2.h is like


#define MAX_VERTICES 8000 // Max number of vertices (for each object)
#define MAX_POLYGONS 8000 // Max number of polygons (for each object)

// vertex type
typedef struct{
float x,y,z;
}vertex_type;

// The polygon (triangle), 3 numbers that aim 3 vertices
typedef struct{
int a,b,c;
}polygon_type;

// The mapcoord type, 2 texture coordinates for each vertex
typedef struct{
float u,v;
}mapcoord_type;

// The object type
typedef struct {
char name[20];

int vertices_qty;
int polygons_qty;

vertex_type vertex[MAX_VERTICES];
polygon_type polygon[MAX_POLYGONS];
mapcoord_type mapcoord[MAX_VERTICES];
int id_texture;
} obj_type, *obj_type_ptr;



I seem to get errors if i add a constructor. Any advise or help would be greatly appreciated in how i can get the car into the skymap.
cheers

trinitrotoluene
11-27-2008, 04:20 PM
First are you able to draw the car model alone without texture? Do you use lighting? Do the car model need a scaling factor glScale (http://www.opengl.org/sdk/docs/man/xhtml/glScale.xml) to fit inside your sky box?

nick2price
11-27-2008, 04:41 PM
The car works fine as its own project. I havnt attempted to put it in the skybox yet. This is what i am trying to achieve now but i am unsure of how to go abouts this.

trinitrotoluene
11-27-2008, 05:15 PM
Ok, then you must check first if it will fit inside your sky box. If you can calculate the bounding box (maybe estimate it) of your car then you will know if you need to scale your car or your sky box. After, this should be very easy to place it in the center of the sky box.

nick2price
11-27-2008, 05:33 PM
I am not sure how to work out the bounding box, very new, but from visual i would say that the car would have no problem fitting in the skymap. The next step would be to learn how to get it in which is whats getting me. So, i would have to do it through my main class, but what would be the procedure?

trinitrotoluene
11-27-2008, 06:02 PM
If the center of the car is near the origin and the center of your sky box is the origin, just draw the car and all will be fine. But if the center of your car is not at the origin (maybe the person who model it didn't take care of that thing), you have to translate it back with glTranslatef(...). The translate value are to be find. Notice that most 3d modeler have the Z axis up (Y axis in OpenGL) , so your car may appear lying on a side. So maybe you will have to rotate it too. But you write before that you already achieve to draw the car successfully.



glTranslatef(...)// Elevate it to make the tire of the car over the road T3
glRotate(...)//Rotate it if needed T2
glTranslate(...)//Put the origin at the center of the car T1
draw_car()

This is a trivial transform to perform. You know, transformation in OpenGL will be performed in the inverse order they are declared.

nick2price
11-27-2008, 06:36 PM
I done some changes and added the methods to draw the car into my skymap class.



#include "stdafx.h"
#include <GL/glut.h>
#include <windows.h>
#include <stdio.h> //for file access
#include <gl\gl.h>
#include "skybox.h"
#include "glbmp.h"
#include "coursework2.h"
#include "3dsloader.h"
#include "texture.h"

obj_type object;

bool skybox::LoadTexture(unsigned int & aTexture, const char * bitmap_file)
{
glbmp_t bitmap; //object to fill with data from glbmp


if(!glbmp_LoadBitmap(bitmap_file, 0, &amp;bitmap))
{
fprintf(stderr, "Error loading bitmap file: %s\n", bitmap_file);
}

//generate and bind the OpenGL texture
glGenTextures(1, &amp;aTexture);
glBindTexture(GL_TEXTURE_2D, aTexture);

//copy data from bitmap into texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.width, bitmap.height,
0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);

//set up texture filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

//free the bitmap
glbmp_FreeBitmap(&amp;bitmap);

return true;
}



void skybox::Init() {

OFFSET = 1/512.0; //set offset value for skybox

rot_x = 0.0; rot_y = 0.0;



LoadTexture(texture[0], "images/1.bmp");
LoadTexture(texture[1], "images/2.bmp");
LoadTexture(texture[2], "images/3.bmp");
LoadTexture(texture[3], "images/4.bmp");
LoadTexture(texture[4], "images/5.bmp");
LoadTexture(texture[5], "images/6.bmp");

}

void skybox::Init2(){

glClearColor(0.0, 0.0, 0.0, 0.0); // This clear the background color to black
glShadeModel(GL_SMOOTH); // Type of shading for the polygons


// Projection transformation
glMatrixMode(GL_PROJECTION); // Specifies which matrix stack is the target for matrix operations
glLoadIdentity(); // initialize the projection matrix as identity
// gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,10.0f,10000.0f); // define the "viewing volume"

glEnable(GL_DEPTH_TEST); // enable the depth test (also called z buffer)
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); // Polygon rasterization mode (polygon filled)

glEnable(GL_TEXTURE_2D); // This Enable the Texture mapping

Load3DS (&amp;object,"GTR.3ds");

object.id_texture=LoadBitmap("body.bmp"); // The Function LoadBitmap() return the current texture ID


}

//This is where the magic happens
void skybox::draw() {

glPushMatrix();
glRotated(rot_x, 1.0, 0.0, 0.0); //Rotate around the x axis
glRotated(rot_y, 0.0, 1.0, 0.0); //Rotate around the y axis

glColor3f(1.0f,1.0f,1.0f); //Set colour to White
glEnable(GL_TEXTURE_2D); //Enable texture mapping
glDisable (GL_DEPTH_TEST); //Disable depth testing

//before you can use a texture you have to bind it
glBindTexture(GL_TEXTURE_2D, texture[0 + text_offset]);

glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET,0.0 + OFFSET); glVertex3d (-10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET,0.0 + OFFSET); glVertex3d (-10.0,-10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET,1.0 - OFFSET); glVertex3d (-10.0,10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET,1.0 - OFFSET); glVertex3d (-10.0,10.0,10.0);

glEnd ();

glBindTexture(GL_TEXTURE_2D, texture[1 + text_offset]);
glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET,0.0 + OFFSET); glVertex3d (-10.0,-10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET,0.0 + OFFSET); glVertex3d (10.0,-10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET,1.0 - OFFSET); glVertex3d (10.0,10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET,1.0 - OFFSET); glVertex3d (-10.0,10.0,-10.0);
glEnd ();

glBindTexture(GL_TEXTURE_2D, texture[2 + text_offset]);
glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,0.0 + OFFSET); glVertex3d (10.0,-10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,0.0 + OFFSET); glVertex3d (10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,1.0 - OFFSET); glVertex3d (10.0,10.0,10.0);
glNormal3d (0.0,0.0,10.0); glTexCoord2d (0.0 + OFFSET ,1.0 - OFFSET); glVertex3d (10.0,10.0,-10.0);

glEnd ();

glBindTexture(GL_TEXTURE_2D, texture[3 + text_offset]);
glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,0.0 + OFFSET); glVertex3d (10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,0.0 + OFFSET); glVertex3d (-10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,1.0 - OFFSET); glVertex3d (-10.0,10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,1.0 - OFFSET); glVertex3d (10.0,10.0,10.0);

glEnd ();

glBindTexture(GL_TEXTURE_2D, texture[4 + text_offset]);
glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,0.0 + OFFSET); glVertex3d (-10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,0.0 + OFFSET); glVertex3d (10.0,-10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,1.0 - OFFSET); glVertex3d (10.0,-10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,1.0 - OFFSET); glVertex3d (-10.0,-10.0,-10.0);

glEnd ();

glBindTexture(GL_TEXTURE_2D, texture[5 + text_offset]);
glBegin (GL_QUADS);

glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,0.0 + OFFSET); glVertex3d (-10.0,10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,0.0 + OFFSET); glVertex3d (10.0,10.0,-10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (1.0 - OFFSET ,1.0 - OFFSET); glVertex3d (10.0,10.0,10.0);
glNormal3d (0.0,0.0,1.0); glTexCoord2d (0.0 + OFFSET ,1.0 - OFFSET); glVertex3d (-10.0,10.0,10.0);

glEnd ();

//Re-Enable the depth test
glEnable(GL_DEPTH_TEST);
//disable texture mapping
glDisable(GL_TEXTURE_2D);
glPopMatrix();


}

void skybox::draw_car(void){

int l_index;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); // Modeling transformation
glLoadIdentity(); // Initialize the model matrix as identity

glTranslatef(0.0,0.0,-300); // move the object forward (the model matrix is multiplied by the translation matrix)



glBindTexture(GL_TEXTURE_2D, object.id_texture); // set the active texture

glBegin(GL_TRIANGLES);
for (l_index=0;l_index<object.polygons_qty;l_index++)
{
//----------------- FIRST VERTEX -----------------
// Texture coordinates of the first vertex
glTexCoord2f( object.mapcoord[ object.polygon[l_index].a ].u,
object.mapcoord[ object.polygon[l_index].a ].v);
// Coordinates of the first vertex
glVertex3f( object.vertex[ object.polygon[l_index].a ].x,
object.vertex[ object.polygon[l_index].a ].y,
object.vertex[ object.polygon[l_index].a ].z); //Vertex definition

//----------------- SECOND VERTEX -----------------
// Texture coordinates of the second vertex
glTexCoord2f( object.mapcoord[ object.polygon[l_index].b ].u,
object.mapcoord[ object.polygon[l_index].b ].v);
// Coordinates of the second vertex
glVertex3f( object.vertex[ object.polygon[l_index].b ].x,
object.vertex[ object.polygon[l_index].b ].y,
object.vertex[ object.polygon[l_index].b ].z);

//----------------- THIRD VERTEX -----------------
// Texture coordinates of the third vertex
glTexCoord2f( object.mapcoord[ object.polygon[l_index].c ].u,
object.mapcoord[ object.polygon[l_index].c ].v);
// Coordinates of the Third vertex
glVertex3f( object.vertex[ object.polygon[l_index].c ].x,
object.vertex[ object.polygon[l_index].c ].y,
object.vertex[ object.polygon[l_index].c ].z);
}
glEnd();

glFlush(); // This force the execution of OpenGL commands
glutSwapBuffers();

}


Then in my main class, i call it up in a simular way to my skymap


#include "stdafx.h"
#include <GL/glut.h>
#include <windows.h>
#include <stdio.h> //for file access
#include <gl\gl.h>
#include "skybox.h"
#include "glbmp.h"
#include "coursework2.h"
#include "3dsloader.h"
#include "texture.h"

int screen_width=800;
int screen_height=600;

skybox aSkyBox;


GLvoid ReSizeGLScene(GLsizei width, GLsizei height) {

if (height<=0) { height=1; }

glViewport(0,0,width,height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int InitGL(GLvoid) {

glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH); //Try GL_FLAT to see the difference
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //Background colour
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST); //Enables depth testing
glDepthFunc(GL_LEQUAL); //Specifies how Depth testing is done
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Affects quality of colour and texture interpolation
glFrontFace (GL_CCW); //Specifies that the front of a face is defined
//in a Counter Clockwise manner
glCullFace(GL_BACK); //Specifies that the back of faces are not shown
//so OpenGL does not need to draw things twice
glEnable(GL_CULL_FACE); //Enables culling of faces


aSkyBox.Init(); //Initalize the Skybox
aSkyBox.Init2();

return TRUE;
}

void DrawGLScene(GLvoid) {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

aSkyBox.draw();
aSkyBox.draw_car();
glutSwapBuffers();
}

int main(int argc, char **argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(screen_width,screen_height);
glutInitWindowPosition(0,0);
glutCreateWindow("Coursework 2");

glutReshapeFunc(ReSizeGLScene);
glutDisplayFunc(DrawGLScene);
InitGL();
glutMainLoop();

return(0);
}


Without the car drawn, my skymap displays fine. But as soon as i add the line aSkyBox.draw_car(); when i run it i am just displayed with a black screen. What would this generally mean?

trinitrotoluene
11-27-2008, 07:01 PM
ut as soon as i add the line aSkyBox.draw_car(); when i run it i am just displayed with a black screen. What would this generally mean?

You call glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); in your draw_car(void) so all previous rendering is erased. Call glClear and glutSwapBuffer only in the main rendering function.