midimatt 24 Light Poster

why cant i put all my variables outside the methods? whats going to happen?
i trigger every method each time, and each of the methods are simply reused?

Not sure if I understand your question completely so please tell me if I got something wrong.

If your variables are used by multiple methods and they need to store the changes between method calls e.g. a balance variable for a bank account, then you should put these variables outside of the any methods.

If your variables are used across all methods then they will keep their values unless you specifically change them.

public int num = 0;

public void addto()
{
     num++;
}
public void removefrom()
{
     num--;
}

In the code above number will retain its value between calls, if i called add twice and remove once, then the value would be 1;

public void addto()
{
     num = 1
}
public void removefrom()
{
     num--;
}

in this bit of code the add function sets the variable therefore calling add twice and remove once would give the value of 0.

As for putting all of your variables outside of methods, it does make your code a lot harder to read through and debug.

Hope some of this will help you.

-Matt

NewOrder commented: Awesome +0
midimatt 24 Light Poster

I'm getting Linker errors when trying to compile my OpenGL code with Dev C++, the code compiles perfectly on the university machines using Visual Studio.

I've visited several sites that explain how to get openGL to work om Dev C++, and i've followed the steps.

-Installed the Dev Pack.
-added the glut32.dll file
-changed the parameters in the project options

the parameters are "-lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32" i've tried entering all on same line, i've tried 1 line per parameter but still i get linker errors.

i've hit a brick wall and no idea where to go from here.

Here is the code that i have so far(its for drawing a simple robotic arm);

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>


static int shoulder = 0, elbow = 0, wrist = 0, finger1 = 0,finger2 = 0, finger3 = 0;

void init(void)
{
    	glClearColor (0.0, 0.0, 0.0, 0.0);
    	glShadeModel (GL_FLAT);
}


void display(void)
{
     	glClear (GL_COLOR_BUFFER_BIT);
     	glPushMatrix();
     	glTranslatef (-1.0, 0.0, 0.0);
     	glRotatef ((GLfloat) shoulder, 0, 90, 1.0);
     	glTranslatef (1.0, 0.0, 0.0);
     	glPushMatrix();
     	glScalef (2.0, 0.4, 1.0);
	 glColor3f(1,1,1);
     	glutSolidCube (1.0);
     	glPopMatrix();

     	glTranslatef (1.0, 0.0, 0.0);
     	glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0);
     	glTranslatef (1.0, 0.0, 0.0);
     	glPushMatrix();
     	glScalef (2.0, 0.4, 1.0);
	glColor3f(0.9,0.9,0.9);
     	glutSolidCube (1.0);
     	glPopMatrix();

	glTranslatef (1.0, 0.0, 0.0);
     	glRotatef ((GLfloat) wrist, 0.0, 0.0, 1.0);
     	glTranslatef (1.0, 0.0, 0.0);
     	glPushMatrix();
     	glScalef (2.0, 0.4, 1.0);
	glColor3f(0.8,0.8,0.8);
     	glutSolidCube (1);
     	glPopMatrix();

	glPushMatrix();
	glTranslatef (0.5, 0.0, 0.75);
     	glRotatef ((GLfloat) finger1, 0.0, 0.0, 1.0);
     	glTranslatef (1.0, 0.0,
Ancient Dragon commented: Thanks for taking the time to learn how to use code tags correctly :) +24