PDA

View Full Version : plot drop out



o9i8
02-09-2002, 08:23 AM
I have just finished all the primary function on my 3d Modeler source code, It draws in 3D no problem, Ah but It wont remember lines they pop out as soon as a new click is issued, So you get to draw one line then apon drawing the next the first vanishes
any Idea on how to fix this.......Thanks In Advance
regular filling up of variables
glBegin(GL_LINES);
glVertex3f(xb,yb,zb);
glVertex3f(xf,yf,zf);
glutSwapBuffers();
glEnd();
Whats making it vanish lack of numbered array ... reloading in real time what?????

Moz
02-09-2002, 08:29 AM
Don't use doublebuffering, it's as simple as that.

Or if you do, you have to store all your geometry in an array, ready to be drawn, and redraw it all before every swapbuffers.

jwatte
02-09-2002, 02:58 PM
You'll probably get better answers on the beginner board. However, in brief, OpenGL is not a retained mode API. Everytime you call SwapBuffers, you should consider the back buffer (that you're drawing into) to become "undefined" and start over, clearing first, drawing everything you want to be displayed on the screen from scratch.

This means that you have to remember what you want to display on the screen, but that's usually a requirement for modeler programs anyway :-)

o9i8
02-09-2002, 03:58 PM
Hi Moz'jwatte thanks for the info...

Moz If I don't use 2 buffers how will I get what I need on screen, is there some way to do this. Is there some way to say show present drawings. I thought the reason for backbuffer is so you could be seeing the backbuffer wile writing on the other, then when you swap you get updated version of buffer.

[This message has been edited by o9i8 (edited 02-09-2002).]

Moz
02-10-2002, 12:15 AM
Actually,
When you use 2 buffers, you see the front buffer and you draw to the back buffer.

What you should understand is that every time you swap the buffers, the content of the back buffer becomes undefined (actually it depends on the pixel format, but considering it's undefined is a good rule).

What you draw in the back buffer won't update what's in the front buffer when you swap, it will replace it.
Considering the content of the back buffer is undefined, you should clear (using the glClear command) it before drawing, then draw ALL the geometry you want to see in the updated image (and not just the last line that's been added) then swap. This is why you have to store all the geometry you want to display in some structure that's suitable for drawing (e.g. arrays you can draw using vertex arrays).

The reason for doublebuffering is that to display an animation, you cannot use only one buffer. Imagine a scene you want to rotate. If you do that using only one buffer and clear the scene and redraw every time you rotate the scene a little, then you will see some of your geometry flicker. This is because the clear command you have to issue before every new frame will erase all of your scene and some of the lines or polygons that have been drawn just before the glClear will not spend a lot of time onscreen.

If you don't have to move your objects, then you can use a single buffer. When you want to add one line, just draw this one line and flush (glFlush). However, if some of your display window gets hidden by some other window, you will have to redraw all of the hidden geometry (better say redraw everything). So you'll need some data structure to hold your geometry anyway.

If you have some issues with all this, I suggest you read the red book or post on the beginners board.

o9i8
02-10-2002, 03:44 AM
I always heard there is a call list or that you can push the xyz on the display stack or something along those lines. But now I need an array I new it! I hope open gl isn't as bad as I thought, It is 20 year old technology. I got to get me a GPU and use machine language on it or some wicked VC++

[This message has been edited by o9i8 (edited 02-10-2002).]

Moz
02-10-2002, 04:24 AM
OpenGL is not bad, actually it is the best existing technology for real-time 3D rendering. Direct3D is just the same thing. 3D APIs are tied to 3D hardware architecture ... unless you use some unusual hardware raytracer, you'll have to deal with OpenGL-like stuff.

Then, doing 3D stuff is not trivial, if you're scared by having to manage an array, then don't do any 3D (don't do any programming at all). You don't have to use VC++ to use OpenGL, any compiler is just fine, you can even use other programming languages. And yes, if you want real-time 3D get a GPU. If you don't need real-time, you can still use OpenGL in software, it's easier than programming your own 3D renderer.

OpenGL is a 20 year-old technology? Maybe, but have the laws of physics regarding light changed over the past billion years? Just because they've been used the same way in 3D rendering for 20 years doesn't mean they're outdated now. And by the way, OpenGL is evolving all the time.

You have to go back to the basics, read the red book. This will clear your view on 3D graphics.
The red book: http://dmawww.epfl.ch/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/

jwatte
02-10-2002, 07:07 AM
You seem to be searching for a good structure for your modeling program. If that's the case, try this approach on for size:

set-up:




#include <vector>

struct Vert {
float x; float y; float z;
}; // or whatever you use

vector< Vert > gMyLines;


In your window repaint message handler:




glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnableClientState( GL_VERTEX_POINTER );
glVertexPointer( 3, GL_FLOAT, 0, &amp;gMyLines[0] );
glDrawArrays( GL_LINES, 0, gMyLines.size( ) );
glDisableClientState( GL_VERTEX_POINTER );

wglSwapBuffers( hdc ); // or whatever


When the user adds a line:




void addLine( Vert a, Vert b )
{
gMyLines.push_back( a );
gMyLines.push_back( b );
RedrawWindow( hwnd, windowRect );
}


To support dragging lines, you might want to structure it like so:




bool dragging;

void onMouseDown( Point p ) {
Vert v( p.x, p.y, -1 );
addLine( v, v );
dragging = true;
}

void onMouseMoved( Point p ) {
if( dragging ) {
Vert & v = gMyLines[gMyLines.size()-1];
v.x = p.x; v.y = p.y;
RedrawWindow( hwnd, windowRect );
}
}

void onMouseUp( Point p ) {
if( dragging ) {
Vert & v = gMyLines[gMyLines.size()-1];
v.x = p.x; v.y = p.y;
dragging = false;
RedrawWindow( hwnd, windowRect );
}
}


This implements the MacOS-style dragging: click to place the first point, and drag (with mouse down) to extend the line; release when it's at the right position. You can easily extend it once you have the basic version going, of course.

If you're using glx or glut or something instead of Win32, substitute the appropriate calls for SwapBuffers and RedrawWindow.



[This message has been edited by jwatte (edited 02-10-2002).]

o9i8
02-10-2002, 06:06 PM
Hi Thanks I will take a look at it and see what you wrote, any way it all ready has all the cool line drag stuff and it draws 3D all ready I need to know if there is a good way to keep the screen accumulating as I go there must be some simple routine for xyz, something that analizes as it goes, just got to build one.

[This message has been edited by o9i8 (edited 02-12-2002).]

o9i8
02-14-2002, 05:18 AM
Of course you realize this whole thing is no good without the interface to the file system
so I can save the drawing, other wise use-less. There some kinda way to say
and you can tell it any address you want and it will let you store bytes but C++ does not have a straight forward way to store numbers 'ie Data I made a copy of it I got it here somewhere.