I am trying to render a very simple scene by loading various parameters from a file (MLC.txt)
When compiling I receive the following error
main.cpp: In function ‘void renderScene()’:
main.cpp:77: error: ‘pBeam’ was not declared in this scope
H
I am trying to render a very simple scene by loading various parameters from a file (MLC.txt)
When compiling I receive the following error
main.cpp: In function ‘void renderScene()’:
main.cpp:77: error: ‘pBeam’ was not declared in this scope
H
#ifndef BEAM_H_
#define BEAM_H_
class Beam{
public:
float *leafBoundary,*leafPosition,parkedPosition;
int leafPairs;
Beam();
Beam(char *file);
void setLeafBoundaries(char *lBoundary, int pairs);
void setLeafPositions(char *lPos, int pairs);
void setLeafPairs(char *lPairs);
void setParkedPosition(char *PP);
void renderCrossHair();
void renderMLC();
~Beam();
};
#endif /* BEAM_H_ */
40
-80\-76\-72\-68\-64\-60\-56\-52\-48\-44\-40\-36\-32\-28\-24\-20\-16\-12\-8\-4\0\4\8\12\16\20\24\28\32\36\40\44\48\52\56\60\64\68\72\76\80
110\110\110\110\110\110\110\110\110\110\110\-4\-15\-18\-17\-15\-19\-16\-24\-23\-22\-20\-20\-22\-23\-24\-27\-29\-28\-29\-27\110\110\110\110\110\110\110\110\110\110\110\110\110\110\110\110\110\110\110\110\27\31\26\15\22\27\29\32\34\33\29\43\44\48\48\51\54\57\13\10\110\110\110\110\110\110\110\110\110
110
Somehow the last paragraph of my post was lost ...
If I add the line Beam *pBeam into the void renderScene() function then a window appears but nothing is shown. I inserted a comment line to print the coordinates to a terminal ,which does not appear
Somehow the last paragraph of my post was lost ...
If I add the line Beam *pBeam into the void renderScene() function then a window appears but nothing is shown. I inserted a comment line to print the coordinates to a terminal ,which does not appear
Lets see your main.cpp file and the rest of what you have because I'm pretty sure you are not declaring "beam" correctly.
Lets see your main.cpp file and the rest of what you have because I'm pretty sure you are not declaring "beam" correctly.
good point - see attachment
Thanks in advance
#include <qapplication.h>
#include "metric_conversion.h"
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
Metric_Conversion w;
w.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
Pretty sure that is the wrong main.cpp you linked.
Pretty sure that is the wrong main.cpp you linked.
okay now I've got it right - phew!
#include <cstdlib>
#include <GL/glut.h>
#include <iostream>
#include<cstdio>
#include <ctype.h>
#include <cmath>
#include <ctime>
#include <cstring>
#include <fstream>
#include <cassert>
#include "Beam.h"
using namespace std;
// Prototypes
int main(int argc, char * argv[]);
void init();
void handleKeypress(unsigned char key, int x, int y);
void initRendering();
void handleResize(int w, int h);
void renderScene();
//Called when a key is pressed
void handleKeypress(unsigned char key, int x, int y) {
switch (key) {
case 27: //Escape key
exit(0);
}
}
//Initializes 3D rendering
void initRendering() {
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
}
//Called when the window is resized
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(9.148, (double)w / (double)h, 800.0, 1500.0);
}
void init(){
glClearColor(0.0,0.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
glLoadIdentity(); //Reset the drawing perspective
glTranslatef(0.0f, 0.0f, -1000); //Move forward Z (mm) units
glRotatef(0.0, 0.0f, 0.0f, 1.0f); //Rotate "camera" about the z-axis (collimator)
glRotatef(-155.0, 0.0f, 1.0f, 0.0f); //Rotate the "camera" by camera_angle about y-axis (gantry)
glRotatef (90.0f,1.0f,0.0f,0.0f); // rotate "camera" by 90 degrees about x-axis
glTranslatef(-11.0f,189.0f,51.0f); //re-define origin of world coordinates to be (11,-189,-51) - applied to all polygon vertices
// Define a colour array for ease of specification
GLfloat colours [][3]={
{0.0,0.0,0.0}, // black [0]
{1.0,0.0,0.0}, // red [1]
{1.0,1.0,0.0}, // yellow [2]
{1.0,0.0,1.0}, // magenta [3]
{0.0,1.0,0.0}, // green [4]
{0.0,1.0,1.0}, // cyan [5]
{1.0,1.0,1.0}, // white [6]
{0.5,0.5,0.5} // grey [7]
};
}
void renderScene(){
// Beam *pBeam;
std::cout << "\nStart rendering scene now ... ";
pBeam->renderMLC();
}
int main(int argc, char * argv[]){
Beam *pBeam=NULL;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(210, 160); // 210 x 160 for Syn
//Create the window
glutCreateWindow("Display window: Draw MLC");
pBeam=new Beam(argv[1]);
// b1 = beam;
initRendering();
init();
std::cout << "\nWhere is the problem? \n";
//Set handler functions
glutDisplayFunc(renderScene);
std::cout << "Here?\n";
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
std::cout << "Or here?\n";
glutMainLoop();
std::cout << " done!";
delete pBeam;
std::cout << "\nBeam object destructuted!\n";
return 0;
}
I see that you put Beam *pBeam=NULL;
in your main() function. This does not mean that pBeam is now going to be a global variable that everything can use. I made a really crappy 2D batman game in OpenGL and having a clean layout is key and that pretty much means make a bunch of files that divide your program into sections (I see you did that with your class and that is a good start).
Anyways you should be able to fix the problem you have by declaring pBeam in a global scope (by declaring it outside of functions at the top of your file).
If you run into any other problems feel free to ask.
>>Anyways you should be able to fix the problem you have by declaring pBeam in a global scope (by declaring it outside of functions at the top of your file).
You should but that is not a good solution. Don't start of learning bad practices. It will only come back to haunt you. I can't look at your code right now, but I might get back at this later.
I totally agree that making everything global is a really poor way of coding but for projects like this where you are going to have your primary elements of the game being used lots you might as well make it global since you know you will be using it all the time.
If you have another way of doing it I too would like to see.
Thanks for all your help. I, like sfuo, would be interested in learning another way of doing this without defining stuff globally. But it works!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.