PDA

View Full Version : Displaying changing lines in OpenGL



cheeyw
01-18-2008, 07:56 PM
I am new to OpenGL. I am coding in Visual C++ 2005 environment, and I have some problem of calling the display.


glutDisplayFunc(display);

The "display" is a callback function, so i declared it as a static function in the header.

static void __cdecl display();

In the display function, i wanted it to read an array from a non static function, and display the lines from there.



glClearColor(0,0,0,0);//set the background color to black
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);

x=((COpenGL*) pDummy)->myArray[i].x;
y=((COpenGL*) pDummy)->myArray[i].y;

for(i=0;i<10;i++)
{
x=mySelf->laser[i].x;
y=mySelf->laser[i].y;
z=0.0;
glVertex3f(x,y,z);
}

glBegin(GL_LINE_STRIP);



Each array represents a frame that i want to display in the OpenGL window. These frames will be continously streaming in, and in the openGL window will form an animation of different frames.

Unfortunately, it cannot be done as Visual C++ reported a wrong type of casting in

((COpenGL*) pDummy)

What is wrong here?
Are there any other alternatives?

Zengar
01-19-2008, 04:38 AM
Well, you realize that this has nothing at all to do with OpenGL? You do have GL errors in your code hovewer: the glVertex calls shoudl be put inside ghBegin ... glEnd block (look glBegin up in the documentation).

As for your question, I have no idea about C++ type system, but you will also don't say what kind of variable pDummy ist and why do you need to cast it to the COpenGL* type (what is this type anyway?). Also, there is a contradiction in your code: you redeclare the x and y variables in your loop, so that pDummy lines are absolutely irrelevant to your program.

s_ridenour
01-20-2008, 12:29 AM
You need to tell us the actual error message as reported by VC++ (also, what version of GLUT).

I don't know why you're throwing __cdecl in display()'s prototype, either. Just "static void display(void);" should be enough.

Also, is this C (.c) or C++ (.cpp)?