Jump to content
  • Advertisement
Sign in to follow this  
bushimports

Problem Using Object Oriented c++

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

I have been trying to learn object oriented programming in c plusplus I seem to do ok with console programs, but I can't seem to make anything work when I try to use it with glut/Open GL. I can use glut and open GL by themselves ok although I still have a lot to learn about it. Below is the code where I am getting 2 compiler errors. I have added comments where I am getting the errors. I can't see any problem but it won't compile. It is always possible that even when I get past that, more errors could pop up. Much Thanks up front to anyone who will help me with this. L.J. Bush
void circle::draw(){             
int i;
   
   glPushMatrix();   
   glEnable(GL_LINE_SMOOTH);
   glLineWidth(2);                          
   glBegin(GL_LINE_LOOP);
   for(i=0; i <= pnts; i++){
   float angle = 2 * PI * 0.5 / pnts; // expected primary-expression before '=' token                glNormal3f(cos(angle), 0, -sin(angle));
   angle = 2*PI * i / pnts;          // expected primary-expression before '=' token 
   glVertex3f(Cx,Cy * -cos(angle),Cz * sin(angle));
       }
       glEnd();
       glPopMatrix();    
}

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Shakedown
Your problem lies in the for loop, perhaps you've not defined i? You need to add 'int'.

The i is defined at the very beginning of the routine body as an int variable (unfortunately the OP shows a blank line between it and the remaining body as well as some confusing indentation, so it can be overlooked simply).

Share this post


Link to post
Share on other sites
No I don't think angle is a macro, as far as I know it is just a variable.
I tried using int inside with i=0 and got rid of the indentations,
but that did no good.
I am using cmath and defining pi in my header file.Thanks Jody Bush

Share this post


Link to post
Share on other sites
Quote:
Original post by haegarr
Please verify that angle isn't defined as a macro.


yes.

Share this post


Link to post
Share on other sites
I'd guss you wrote something like this in your PI macro:
#define PI = 3.141562654;
when it should be just:
#define PI 3.141562654

Either that or 'angle' is a macro. Try renaming it to 'angle2' and see if that fixes it.

Share this post


Link to post
Share on other sites
Thanks guys. thanks iMalc, you were right I did define PI with an assignment operator,even I should have known better than that. The program did compile
but it has a bug. I get a window that has whatever was behind it in it.
I have two more member functions,one for setting the x,y,z position of the circle,the radius,and the number of circle points, and one to set the color. I must have something wrong there I don't know. I hacked over this several days thinking I could figure it out before I came over here for help,but I have not been able to get it.I did try the other suggestions but they did not help.Here is the code for the other two functions.All of you guys were right about the macro, I had no idea that PI was a macro. Much thanks L.J. Bush

void circle::set(GLfloat x, GLfloat y, GLfloat z, float r, int pnts){
Cx = x;
Cy = y;
Cz = z;
radius = r;
circlePoints = pnts;
}

void circle::setColor(GLfloat r,GLfloat g,GLfloat b){
glColor3f(r,g,b);
}

Share this post


Link to post
Share on other sites
Seeing the now covered screen section as background in an OpenGL view hints at using double buffering but not having swapped the background (a.k.a. render) buffer to the foreground after rendering. Also don't forget to initialize and invoke glClear(...).


There is another problem I see with your circle::setColor(...) routine. A routine with such a signature is commonly used as so-called "setter" and is normally expected to store the overhanded values in member variables of the circle class, so that they are associated with the particular circle instance. Instead, your implementation only invokes glColor3f(...). So that color is set as current OpenGL color, but that will be active only up until the next invocation of glColor. There is especially no definite association of the color with the circle instance.

Hence I suggest the following: Let circle::setColor(...) store the color in member variables. Add belonging getters to the circle class. Let the render routine circle::draw(..) invoke glColor with the member variables as arguments.


Furthur, I'm unhappy that C++ does not introduce more restrict rules on spellings. That hat lead to a half dozen of variations. People often tend to adopt the writing seen in the book learning C++ from. However, it seems me that most people prefer to start class names with uppercase letters. Please consider to do so, too; e.g. let the class be named "Circle."

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!