edit: don't worry, forget I said anything :icon_redface:
tux4life commented: Thanks for using code tags, and for being nice :) +22
edit: don't worry, forget I said anything :icon_redface:
I have downloaded the source but I don't know what to do now, if I make a new glut project and select the source folder and it says its invalid, what do I do now?
oh. no i didnt. i just downloaded the glut-3.7.6-bin. so i download the source then...
yay i solved something:):):):icon_cheesygrin:
yes I followed that tutorial, but it doesn't work. when I try to compile anything I get errors like [glut function name] wasn't declared in this scope and unused variable [glut function name]. In that tutorial it talks about putting a .a file somewhere, but there wasnt a .a file in the download?
have you tried this code?
#include <stdio.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
class M
{
public:
int value1;
int value2;
};
class P
{
public:
int sum(M n){
int t = 2;
int s = n.value2 + t;
return s;
}
};
int main(){
M m;
P p;
m.value1 = 1;
m.value2 = 2;
int res = p.sum(m);
cout << "sum is: " << res;
cin.get();
return 0;
}
I compiled it with minGW in code blocks and it worked fine (after I added return; and took main() out of a class) so maybe its something to do with the compiler/ ide your using
so if I was making a game I would use both then, open GL to draw to the screen and glut to handle input. thanks
what is the difference between openGL glut and openGL?
ok then, openGL as a priority
and um... why win32 api? what use will this be to me?
ok, i will learn a bit of win32 from here:
http://winprog.org/tutorial/
then i will have a look at:
http://www.videotutorialsrock.com/index.php
thanks :icon_cheesygrin:
as I said i am new to classes, with a few minutes of tinkering I moved the implamentation of pet.edit() to after the function declarations and the class to above the functions but below the global variables. that is a better way though, I will change it. thanks for teaching me something
:)
you know i just came to that conclusion when I reset the code to an earlier date when it worked, and remade the class, it didnt work so i put it where i put the pet struct! and it worked.
(I'm learning)
and the reason I didn't figure out the bug in the fist place is because I didn't know whether I could use functions inside a class
and thanks for everyones help ;)
have fun (sarcastic)
OK, ill give you the whole poject, this is my first big project in c++ (I know I'm stupid and shouldn't start big, but it worked until I added classes)
be warned its over 1600 lines of code (and I don't want to waste too much of your time)
/* **********************************
* my first ever c++ game *
title: Pet Keeper
description:manage a group of pets
date start: 16/08/2009
date finish:
copywrite: none
company: Gazelle gaming
programmers: MatthewB;
confidential: 0/10
average rating: 0% (0 reviews)
type: open source console application
genre:
content rating: 3+
difficulty rating:
***********************************/
#include <iostream> //to interact with the console
#include <string> //to use the string variable
#include <fstream> //to work with files
#include <vector> //to use the vector dynamic array
#include <cstdlib> //to genarate random numbers
#include <time.h> //to use the time as the random number seed
class Pet {
public:
//constructor
Pet(std::string Name, unsigned long Age, char Gender, std::string Species) {
Name = this->Name;
Age = this->Age;
Gender = this->Gender;
Species = this->Species;
}
//desructor
~Pet() {}
//attributes
std::string Name;
unsigned long Age;
char Gender;
std::string Species;
void Edit(unsigned short x) {
cls();
std::cout<< "\n"
<< "press 1: to edit the Name: " << Pets[x].Name << "\n"
<< "press 2: to edit the Age: " << Pets[x].Age << "\n"
<< "press 3: to edit the Gender: " << Pets[x].Gender << "\n"
<< "press 4: to edit the species: " << Pets[x].Species << "\n\n"
<< "or press 5: to edit everythig\n";
char EditSelection;
std::cin>> EditSelection;
if(!std::cin.good()) {
std::cin.clear();
delete &EditSelection;
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
EditPet();
}
switch(EditSelection) {
case '1':
cls();
std::cout<< "\n" << "Enter the pets name:";
std::cin >> Pets[x].Name;
if(!std::cin.good()) {
std::cin.clear();
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
cls();
EditPet();
}
break;
case '2':
cls();
std::cout<< "Enter the pets age:";
std::cin >> Pets[x].Age;
if(!std::cin.good()) {
std::cin.clear();
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
cls();
EditPet();
}
break;
case '3':
cls();
std::cout<< "Enter the pets gender (M/F):";
std::cin >> Pets[x].Gender;
if(!std::cin.good()) {
std::cin.clear();
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
cls();
EditPet();
}
switch(Pets[x].Gender) {
case 'm':
Pets[x].Gender = 'M';
break;
case 'f':
Pets[x].Gender = 'F';
break;
case 'M':
case 'F':
break;
default:
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
cls();
EditPet();
break;
}
break;
case '4':
cls();
std::cout<< "Enter the pets species:";
std::cin >> Pets[x].Species;
if(!std::cin.good()) {
std::cin.clear();
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
cls();
EditPet();
}
break;
case '5':
cls();
std::cout<< "\n" << "Enter the pets name:";
std::cin >> Pets[x].Name;
if(!std::cin.good()) {
std::cin.clear();
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
cls();
EditPet();
}
std::cout<< "Enter the pets age:";
std::cin >> Pets[x].Age;
if(!std::cin.good()) {
std::cin.clear();
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
cls();
EditPet();
}
std::cout<< "Enter the pets gender (M/F):";
std::cin >> Pets[x].Gender;
if(!std::cin.good()) {
std::cin.clear();
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
cls();
EditPet();
}
switch(Pets[x].Gender) {
case 'm':
Pets[x].Gender = 'M';
break;
case 'f':
Pets[x].Gender = 'F';
break;
case 'M':
case 'F':
break;
default:
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
cls();
EditPet();
break;
}
std::cout<< "Enter the pets species:";
std::cin >> Pets[x].Species;
if(!std::cin.good()) {
std::cin.clear();
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
cls();
EditPet();
}
break;
default:
cls();
std::cout<< "the input is invalid \n"
<< "press enter to return to the main menu";
EmptyBuffer();
std::cin.get();
DisplayMenu();
break;
}
cls();
std::cout<< "Pet sucsessfully Edited.\n"
<< "the new data is:\n\n"
<< "Name: " << Pets[x].Name << "\n"
<< "Age: " << Pets[x].Age << "\n"
<< "Gender: " << Pets[x].Gender << "\n"
<< "Species: " << Pets[x].Species << "\n\n"
<< "press enter to return to the main menu";
EmptyBuffer();
std::cin.get();
DisplayMenu();
}
};
class Activity {
public:
//constructor
Activity(std::string Text, std::string Species, bool ForAll) {
Text = this->Text;
Species = this->Species;
ForAll = this->ForAll
}
//destructor
~Actvity() {}
//attributes
std::string Text;
std::string Species;
bool ForAll;
};
/*
struct pet{
std::string Name;
unsigned long Age;
char Gender;
std::string Species;
};
*/
struct Activity{
std::string Text;
std::string Species;
bool ForAll;
};
//declare global variables
std::vector<pet> Pets;
std::vector<Activity> Activities;
unsigned long GameTime;
//declare function prototypes
void Save(void);
void Load(void);
void AddPet(void);
void AddActivity(void);
void EditActivity(void);
void ListPets(void);
void ListActivities(void);
void DisplayMenu(void);
void DisplayHelp(void);
void DeleteMenu(void);
void cls(void);
void EmptyBuffer(void);
void Sleep(unsigned int mseconds);
void RunSimulation(void);
int main(void) {
DisplayMenu();
return 0;
}
//functions
//pet functions
void AddPet(void) {
cls();
pet TmpPet; //load all the data into a temporary variable
std::cout << "you chose to add a new pet!" << "\n";
EmptyBuffer();
std::cout<< "\n" << "Enter the pets name:";
std::getline(std::cin, TmpPet.Name);
if(!std::cin.good()) {
std::cin.clear();
delete &TmpPet;
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
EmptyBuffer();
std::cin.get();
AddPet();
}
std::cout<< "Enter the pets age:";
std::cin >> TmpPet.Age;
if(!std::cin.good()) {
std::cin.clear();
delete &TmpPet;
cls();
std::cout<< "the input is invalid\n"
<< "press enter to start again";
I understand what your saying but I have been programming for about a year and I think I am ready, as I can go at my own pace, and I am going to get a book to learn from. I'm asking because I don't know where to go from here.
I want to learn one of the api's but which one would be better to learn. would openGL do everything that direct3d can?
Yes sorry, I wrote that in a hurry, but that isn’t the problem with the other code. I know that sort of defeats the object of the example but with the code I wrote I had included all the things you mentioned and still didn’t work. the function had a prototype and the class had a semicolon. but the compiler said that the function was not declared in the scope. however i will look through the code again and see if it was somthing else
how can I use a function inside an object?
(the code is too long to put here but here's a replica)
class example {
public:
example();
~example();
void doSomthing() {
afunction();
}
}
void afunction() {
//do more things
}
in this example i wouldnt NEED to use a function but I do need to in my code.
when I try to compile the program I get errors like:
error: 'functionName' was not declared in this scope. and
error: unused variable 'functionName'
how much more do i need to know then? i can:
print to a console (obviously)
take user input
use files
use loops (for, while, do)
use decisions (if, if else, switch ect)
and i grasp the concept of how memory is allocated
and i am begining to use classes (and i understand constructors/destructors)
and this isnt the first language i have programmed in.
I have recently learnt the basics of c++ but I want to advance to making proper GUI's (and games) but I don't know what to use.
I think the two most popular libraries are OpenGL and Direct3d but I'm not sure which one to use.
could you guide me in the right direction:)