Jump to content
  • Advertisement
Sign in to follow this  
pat_stevenson

OpenGL My Mars Lander.

This topic is 2707 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

As an class assignment me and a friend have to make a lander type game using OpenGL, GLUT and C++. I've been working away at it and and I've got an error that I just don't know how to fix. The assignment is also supposed to help us grasp the concept of Object Oriented Programming so the game is split into several headers and .cpp files. Would anyone mind having a look at my code to see if you can see the error and maybe if you don't mind give me a few pointers on where to go from what i've got. I've got a feeling the whole code will have to be looked at to see where I've went wrong so I would rather PM someone a link rather than put my code up in its entirety. I'll also PM the assignment specification aswell just to let you guys know what I have to achieve. Also I'm looking for some pointers and a helping hand and not someone to complete/or take over my project. i actually enjoy doing this so please let me still have the satisfaction of doing the majority myself.

Thanks guys, hope to hear from you all soon.
Pat.

Share this post


Link to post
Share on other sites
Advertisement
Describe the problem, if you can't then no one can really help you. Might be useful to describe the main objects and how they interact. No one really wants to look through piles of code so the more you can narrow things downt he more effective any help will be.

Share this post


Link to post
Share on other sites
It really isn't piles of code tho. theres a bitmap class split into a header and a .cpp file, that reads bitmaps into the program and displays. a lander class again split into a header and .cpp file and a main.cpp file. It really isn't a complicated or large program and I thought that people were members of this site because they enjoy looking through code. I know I enjoy it thats why I chose it as a career path. But if you insist the error is in the lander.h file in this line

bitmap = new Bitmap(filename, true);


It says missing type specifier. Ideas?

#include "Bitmap.h"

class Lander
{
public:
Lander (char* filename, float ix, float iy);

bitmap = new Bitmap(filename, true);




void move(float dx, float dy);
void show();
float altitude();
float velocity();
bool IsLanded();

private:
Bitmap *bitmap;

float gravity, terminal_velocity, x, y;




};

Share this post


Link to post
Share on other sites
Ah thats an easy one fortunatly.

bitmap [color="#666600"]= [color="#000088"]new [color="#660066"]Bitmap[color="#666600"](filename[color="#666600"], [color="#000088"]true[color="#666600"]);

That should go in the constructor I assume. In your Lander.cpp or whatever it is
Lander::Lander(char *filename, float ix, float iy)
{
bitmap = new Bitmap(filename, true);
}


If that class is declared in a cpp file then you can just do it right there as it is:


class Lander
{
public:
Lander(char *filename, float ix, float iy)
{
bitmap = new Bitmap(filename, true);
}



One suggestion I would make and it's great if you start doing it right off is to name your member variables (variables in a class) so its: m_(name), i.e. m_Bitmap, rather than just bitmap. Its somewhat of a convention and a good habit.

Share this post


Link to post
Share on other sites
Thanks dude I really appreciate it. I'm also getting some errors in my lander.cpp file that say

1>c:\users\patrick\desktop\bitmap test\lander.cpp(8): error C2084: function 'Lander::Lander(char *,float,float)' already has a body
1> c:\users\patrick\desktop\bitmap test\lander.h(7) : see previous definition of '{ctor}'
1>c:\users\patrick\desktop\bitmap test\lander.cpp(23): warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
1>c:\users\patrick\desktop\bitmap test\lander.cpp(23): warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


#include "lander.h"
#include <GL/glut.h>
#include "Bitmap.h"


Lander::Lander (char* filename, float ix, float iy)
{
x = ix; y = iy;
show();
}

void Lander::move(float dx, float dy)
{
x += dx;
y += dy;
show();

}

void Lander::show()
{
bitmap->drawAt(x,y);
}

Share this post


Link to post
Share on other sites
The error message is clear... You defined the same constructor two times... Did you define it once within the class body and then again in the .cpp file?

Share this post


Link to post
Share on other sites
Did you sign up for some kind of game or graphics course that uses C++... without first knowing C++??

Share this post


Link to post
Share on other sites

Thanks dude I really appreciate it. I'm also getting some errors in my lander.cpp file that say

1>c:\users\patrick\desktop\bitmap test\lander.cpp(8): error C2084: function 'Lander::Lander(char *,float,float)' already has a body
1> c:\users\patrick\desktop\bitmap test\lander.h(7) : see previous definition of '{ctor}'
1>c:\users\patrick\desktop\bitmap test\lander.cpp(23): warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
1>c:\users\patrick\desktop\bitmap test\lander.cpp(23): warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Sounds like you used both of my suggestions, you only needed one. I'd suggest using the one that goes in the cpp file. The conversion warnings you can probably ignore but if you want to get rid of them, add .0f to the end of any number you are passing in (assuming your doing Lander(filename, 1, 1) then do Lander(filename, 1.0f, 1.0f)) or similar).

Share this post


Link to post
Share on other sites
hey guys I'm trying to get user input using glutSpecialFunc can someone tell me where I'm going wrong please?

//main.cpp

#include"Bitmap.h"
#include<gl/glut.h>
#include "lander.h"
#include <iostream>
#include <cmath>
//#include "random.h"



#define windowWidth 800
#define windowHeight 600

bool left_key;
bool right_key;
bool up_key;
float dx;
float dy;


Bitmap *bitmap;
Bitmap *bitmap2 = NULL;
Lander *lander;

void display(){
glClear(GL_COLOR_BUFFER_BIT);
// Draw the background...
bitmap->draw();
if(bitmap2)
bitmap2->drawAt(0, 0);
if(lander)
lander->show();
glFlush();
}

void init(){
// Just a bitmap file, with transparency enabled (true)...
bitmap = new Bitmap("background.bmp", false);
bitmap2 = new Bitmap("ground.bmp", true);
lander = new Lander("lander.bmp",400, 550, 0, 0);
}



/*void keyboard(unsigned char key, int x, int y){
switch (key) {
case 'w': // up
//insert move function here
break;

case 'd': //right
//insert move function here
break;

case 'a': //left
//insert move function here
break;

}

} */
void update()
{
lander->update();
glutPostRedisplay();
}

void timer(int value)
{
update();
glutTimerFunc(40, timer, 0);
}


void special_keys(int value, int x, int y)
{
switch (value) {
case GLUT_KEY_LEFT:
left_key = true;
dx += 15;
break;

case GLUT_KEY_RIGHT:
right_key = true;
dx += -0.8;
break;

case GLUT_KEY_UP:
up_key = true;
dx += 0.8;
break;

break;

//case GLUT_KEY_ESC:
//end program
//break;

}
}


int main(int argc,char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(windowWidth, windowHeight);
glutCreateWindow("Mars Lander by Michael McGuire and Patrick Stevenson");
glClearColor(1.0, 1.0, 0.0, 0.0);
gluOrtho2D(0, windowWidth, 0, windowHeight);
init();
glutDisplayFunc(display);
glutSpecialFunc(special_keys);
//glutSpecialUpFunc(special_up_keys);
glutTimerFunc(0, timer, 0);
glutMainLoop();
delete bitmap;
return 0;
}


lander.h

#include "Bitmap.h"

class Lander
{
public:

Lander::Lander (char* filename, float ix, float iy, float idx, float idy);


void move();
void show();
void update();
void special_keys();
float get_Altitude();
float set_Altitude();
float get_Fuel();
float set_Fuel();

bool IsLanded();


private:
Bitmap *bitmap;

float gravity, terminal_velocity, x, y, fuel, altitude;
bool left_key;
bool right_key;
bool up_key;
float dx, dy;


};

//float Lander::get_Altitude{ return altitude}





lander.cpp

#include "Bitmap.h"

class Lander
{
public:

Lander::Lander (char* filename, float ix, float iy, float idx, float idy);


void move();
void show();
void update();
void special_keys();
float get_Altitude();
float set_Altitude();
float get_Fuel();
float set_Fuel();

bool IsLanded();


private:
Bitmap *bitmap;

float gravity, terminal_velocity, x, y, fuel, altitude;
bool left_key;
bool right_key;
bool up_key;
float dx, dy;


};

//float Lander::get_Altitude{ return altitude}


Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!