Jump to content
  • Advertisement
Sign in to follow this  
Spacekangaroo

OpenGL Object built up from GLRex not displaying

This topic is 2567 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I'm fairly new to OpenGL so apologies for anything really dumb going on here :P

I'm trying to load up an object via my 'Player' class, however it won't render - this object has been generated via GLrex. If I provide code for a simple cube (much like NeHe tutorials) I can render it easily the way I'm doing.

The code for my player class is as follows:


#include <windows.h> // Header File For Windows
#include <stdio.h> // Header File For Standard Input/Output
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <glut.h>

class Player{
private:
GLfloat x, y;
void Makematerial( float r,float g,float b,float a,float s );
public:
void drawMe(GLvoid);
void moveMe(GLfloat xmove, GLfloat ymove);
};

void Player::moveMe(GLfloat xmove, GLfloat ymove){
x = xmove;
y = ymove;
}

void Player::Makematerial( float r,float g,float b,float a,float s )
{
float color[4];
float white[4];
GLfloat surfshine[1] ;
surfshine[0]=s*128.0 ;
color[0]=r;color[1]=g;color[2]=b;color[3]=a;
white[0]=0.5;white[1]=0.5;white[2]=0.5;white[3]=1.0;
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,color);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,color);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,white);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS,surfshine);
}

void Player::drawMe(GLvoid){
GLUquadricObj *qobj;
qobj = gluNewQuadric();
glEnable(GL_NORMALIZE);
gluQuadricNormals(qobj,GLU_SMOOTH);
gluQuadricDrawStyle(qobj,GLU_FILL);

////////////////// box /////////////////////////////////
Makematerial(0.10f,0.08f,0.80f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( 0.0f, 0.0f, 0.0f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( 0,0,0,1);
glScalef( 0.20f, 0.20f, 0.20f);
glTranslatef(0.0,5.0,0.0);
glutSolidCube(10.0);
glPopMatrix();
////////////////// box /////////////////////////////////
Makematerial(0.80f,0.69f,0.42f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( 0.0f, 1.4f, 0.0f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( 0,0,0,1);
glScalef( 0.17f, 0.19f, 0.17f);
glTranslatef(0.0,5.0,0.0);
glutSolidCube(10.0);
glPopMatrix();
////////////////// box /////////////////////////////////
Makematerial(0.75f,0.80f,0.74f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( 0.0f, 1.2f, 0.9f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( 0,0,0,1);
glScalef( 0.19f, 0.12f, 0.03f);
glTranslatef(0.0,5.0,0.0);
glutSolidCube(10.0);
glPopMatrix();
////////////////// box /////////////////////////////////
Makematerial(0.75f,0.80f,0.74f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( -0.8f, 2.7f, 0.9f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( 0,0,0,1);
glScalef( 0.11f, 0.04f, 0.03f);
glTranslatef(0.0,5.0,0.0);
glutSolidCube(10.0);
glPopMatrix();
////////////////// box /////////////////////////////////
Makematerial(0.75f,0.80f,0.74f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( 0.8f, 2.7f, 0.9f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( 0,0,0,1);
glScalef( 0.11f, 0.04f, 0.03f);
glTranslatef(0.0,5.0,0.0);
glutSolidCube(10.0);
glPopMatrix();
////////////////// box /////////////////////////////////
Makematerial(0.18f,0.23f,0.80f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( 0.0f, 3.2f, 0.0f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( 0,0,0,1);
glScalef( 0.27f, 0.02f, 0.30f);
glTranslatef(0.0,5.0,0.0);
glutSolidCube(10.0);
glPopMatrix();
////////////////// box /////////////////////////////////
Makematerial(0.18f,0.23f,0.80f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( 0.0f, 3.4f, 0.0f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( 0,0,0,1);
glScalef( 0.14f, 0.02f, 0.16f);
glTranslatef(0.0,5.0,0.0);
glutSolidCube(10.0);
glPopMatrix();
////////////////// box /////////////////////////////////
Makematerial(0.18f,0.23f,0.80f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( 0.0f, 3.6f, 0.0f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( 0,0,0,1);
glScalef( 0.11f, 0.02f, 0.11f);
glTranslatef(0.0,5.0,0.0);
glutSolidCube(10.0);
glPopMatrix();
////////////////// box /////////////////////////////////
Makematerial(0.18f,0.23f,0.80f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( 0.0f, 3.8f, 0.0f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( 0,0,0,1);
glScalef( 0.07f, 0.02f, 0.06f);
glTranslatef(0.0,5.0,0.0);
glutSolidCube(10.0);
glPopMatrix();
////////////////// box /////////////////////////////////
Makematerial(0.18f,0.23f,0.80f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( 0.0f, 4.0f, 0.0f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( 0,0,0,1);
glScalef( 0.05f, 0.03f, 0.04f);
glTranslatef(0.0,5.0,0.0);
glutSolidCube(10.0);
glPopMatrix();
////////////////// box /////////////////////////////////
Makematerial(0.80f,0.45f,0.13f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( -0.3f, 1.1f, -1.1f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( -49,0,0,1);
glScalef( 0.05f, 0.26f, 0.04f);
glTranslatef(0.0,5.0,0.0);
glutSolidCube(10.0);
glPopMatrix();
////////////////// sphere /////////////////////////////////
Makematerial(0.80f,0.17f,0.06f,1.00f, 0.8f);
glPushMatrix();
glTranslatef( 1.6f, 2.8f, -1.2f);
glRotatef( 0,0,1,0);
glRotatef( 0,1,0,0);
glRotatef( -49,0,0,1);
glScalef( 0.05f, 0.05f, 0.05f);
gluSphere(qobj,10.0,72,72);
glPopMatrix();
///////////////// end of objects ////////
}


To render this object in my main class I have the drawing method do this:


int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,z); // Translate Into/Out Of The Screen By z

//glRotatef(xrot,1.0f,0.0f,0.0f); // Rotate On The X Axis By xrot
//glRotatef(yrot,0.0f,1.0f,0.0f); // Rotate On The Y Axis By yrot
//glBindTexture(GL_TEXTURE_2D, texture[0]);

p.drawMe();


xrot+=xspeed; // Add xspeed To xrot
yrot+=yspeed; // Add yspeed To yrot
return TRUE; // Keep Going

}


I've tried glBegin with several things (polygons etc) around p.drawMe() but no luck :(

I've also attached the class produced by GLrex of the render.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!