PDA

View Full Version : How to eliminate a hidden line?



HanWu
12-19-2002, 02:09 AM
i am doing a cad program which the user can draw a line interactively.The entire object will be redraw again every time i draw a line.But when the number of object is too big the program start to run slowly
I think its something related to the Depth Test and GlDepthFunc() but i don't know how to do it .
Beside that i would like to know why autocad can run smoothly even thought when we are drawing a complicated object (meaning that many points and lines)
Hope someone can help.

V-man
12-19-2002, 07:06 AM
ARB_buffer_region
KTX_buffer_region

to save the background is one quick way.

HanWu
12-19-2002, 04:04 PM
Thanks for your help but can you tell me which function to call ARB_BUFFER_REGION and how to use it.Do u have any example or which homepage to get this example.

V-man
12-20-2002, 09:07 AM
With ARB_buffer_region, the needed parts are

#include <GL/wglext.h>

//We need this
HANDLE HandleToBufferRegion;

//First must create a handle to region
wglCreateBufferRegionARB(hdc, 0, WGL_BACK_COLOR_BUFFER_BIT_ARB | WGL_DEPTH_BUFFER_BIT_ARB);

//For saving the region
wglSaveBufferRegionARB(HandleToBufferRegion, 0, 0, (int)Width, (int)Height);

//For restoring the region
wglRestoreBufferRegionARB(HandleToBufferRegion,
0, 0, //x=0 y=0 lower left corner of the window
(int)Width, (int)Height, //width and height of area to copy
0, 0); //x and y position in buffer region

//To destroy (free video memory)
if(HandleToBufferRegion)
glExtDestroyBufferRegionARB(HandleToBufferRegion);

[This message has been edited by V-man (edited 12-20-2002).]

HanWu
06-10-2003, 09:32 PM
Originally posted by V-man:
With ARB_buffer_region, the needed parts are

#include <GL/wglext.h>

//We need this
HANDLE HandleToBufferRegion;

//First must create a handle to region
wglCreateBufferRegionARB(hdc, 0, WGL_BACK_COLOR_BUFFER_BIT_ARB | WGL_DEPTH_BUFFER_BIT_ARB);

//For saving the region
wglSaveBufferRegionARB(HandleToBufferRegion, 0, 0, (int)Width, (int)Height);

//For restoring the region
wglRestoreBufferRegionARB(HandleToBufferRegion,
0, 0, //x=0 y=0 lower left corner of the window
(int)Width, (int)Height, //width and height of area to copy
0, 0); //x and y position in buffer region

//To destroy (free video memory)
if(HandleToBufferRegion)
glExtDestroyBufferRegionARB(HandleToBufferRegion);

[This message has been edited by V-man (edited 12-20-2002).]

ARB_buffer_region can works well but the problem is not everyone's computer have Geforce(display card), i try to use autocad and it runs smoothly even in a computer that doesn't has graphic card. I try to use glReadPixel and glDrawPixel here is my code

unsigned char *colorSave;

void CSbomView::SaveCurrentView(int index)
{
int port[4];
glGetIntegerv(GL_VIEWPORT,port);

if(colorSave != NULL)
free(colorSave);

colorSave = (unsigned char*)malloc(port[2] * port[3] * 4 * sizeof(unsigned char));


glReadPixels(port[0],port[1], port[2],port[3], GL_BGR_EXT , GL_UNSIGNED_BYTE,
colorSave);
}

void CSbomView::RestoreCurrentView(int index)
{
int port[4];
glGetIntegerv(GL_VIEWPORT,port);

GLint previousColorBuffer;

glPushMatrix();
glLoadIdentity();

if(port[2]<=port[3])
glRasterPos3f(-SIZE, -SIZE* (GLfloat)port[3] / (GLfloat)port[2], 0);
else
glRasterPos3f(-SIZE*(GLfloat)port[2]/(GLfloat)port[3], -SIZE, 0);

glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glGetIntegerv(GL_DRAW_BUFFER, &previousColorBuffer);
glDrawBuffer(GL_BACK);
glDrawPixels(port[2], port[3], GL_BGR_EXT , GL_UNSIGNED_BYTE, colorSave);
glDrawBuffer(previousColorBuffer);
glEnable(GL_DEPTH_TEST);

glPopMatrix();
}
this code work well in Geforce, but very bad in Onboard display card.
can you please show me which part i am wrong and please suggest any efficient way that can apply in any computer that doesn't has a graphic card. Thanks

V-man
06-11-2003, 03:48 AM
"this code work well in Geforce, but very bad in Onboard display card."

There was a recent discussion about this kind of thing.
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/009694.html

I think those onboard solutions (Intel?) are not suitable for 3D. A Gf2MX is ~50$ by now.

HanWu
06-11-2003, 08:18 AM
autocad and a software call ac3d (www.ac3d.org), they can restore background very fast even in Onboard display card. Do you think they use Opengl or Direct3d?if they r using OpenGl, how they do it? use glDrawPixels or have altenative way?

Is it using a texture is faster than glDrawPixels?

Please help me ! Thanks

HanWu
06-11-2003, 10:44 PM
Originally posted by V-man:
"this code work well in Geforce, but very bad in Onboard display card."

There was a recent discussion about this kind of thing.
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/009694.html

I think those onboard solutions (Intel?) are not suitable for 3D. A Gf2MX is ~50$ by now.


static GLuint texName;

void CSbomView::SaveCurrentLamaView(int index)
{
int port[4];
glGetIntegerv(GL_VIEWPORT,port);

if(colorSave != NULL)
free(colorSave);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// glPixelStorei(GL_PACK_ALIGNMENT, 1);
// glReadBuffer(GL_BACK);

colorSave = (unsigned char*)malloc(port[2] * port[3] * 4 * sizeof(unsigned char));

glReadPixels(port[0],port[1], port[2],port[3], GL_RGB , GL_UNSIGNED_BYTE,
colorSave);

glGenTextures(1,&texName);
glBindTexture(GL_TEXTURE_2D,texName);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,port[2],port[3],0,GL_RGB,GL_UNSIGNED_BYTE,colorSave);

}

void CSbomView::RestoreCurrentlamaView(int index)
{
int port[4];
glGetIntegerv(GL_VIEWPORT,port);

GLint previousColorBuffer;

glPushMatrix();
glLoadIdentity();

glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DE CAL);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texName);

if(port[2]>port[3]){
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0);glVertex3f( -SIZE* (GLfloat)port[2] / (GLfloat)port[3], -SIZE, 0);
glTexCoord2f(1.0, 0.0);glVertex3f( SIZE* (GLfloat)port[2] / (GLfloat)port[3], -SIZE, 0);
glTexCoord2f(1.0, 1.0);glVertex3f( SIZE* (GLfloat)port[2] / (GLfloat)port[3], SIZE, 0);
glTexCoord2f(0.0, 1.0);glVertex3f( -SIZE* (GLfloat)port[2] / (GLfloat)port[3], SIZE,0);
glEnd();
}
else {
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);glVertex3f( -SIZE, -SIZE* (GLfloat)port[3] / (GLfloat)port[2], 0);
glTexCoord2f(1.0, 0.0);glVertex3f( -SIZE, SIZE* (GLfloat)port[3] / (GLfloat)port[2], 0);
glTexCoord2f(1.0, 1.0);glVertex3f( SIZE, SIZE* (GLfloat)port[3] / (GLfloat)port[2], 0);
glTexCoord2f(0.0, 1.0);glVertex3f( SIZE, -SIZE* (GLfloat)port[3] / (GLfloat)port[2], 0);
glEnd();
}

glFlush();
glDisable(GL_TEXTURE_2D);

glPopMatrix();
}
Can you check the code please, why my texture just blank. Thanks

Relic
06-12-2003, 01:48 AM
port[2] and port[3] are probably no power-of-two values.

[This message has been edited by Relic (edited 06-12-2003).]

HanWu
06-12-2003, 04:52 AM
Originally posted by Relic:
port[2] and port[3] are probably no power-of-two values.

[This message has been edited by Relic (edited 06-12-2003).]

my screen size is not always power of 2 size, i don't know how to make it to power of 2 size, is it use glTexSubImage2D? Can you just edit the code segment that i have submit. thanks

Relic
06-12-2003, 06:26 AM
No, I thought _you_ get paid for this. http://www.opengl.org/discussion_boards/ubb/wink.gifRemember this is an "OpenGL coding: advanced" forum.

HanWu
06-12-2003, 06:52 AM
Originally posted by Relic:
No, I thought _you_ get paid for this. http://www.opengl.org/discussion_boards/ubb/wink.gifRemember this is an "OpenGL coding: advanced" forum.

Relic, i know its just a simple question, but i need to know it urgent! The reason i ask the question here is i know there are many expert in advance forum. Since i have create a topic in advance forum and i am not going to ask the same question in beginner forum now to avoid duplicate question. Can anyone tell me how to save the background (in any width and height which is not power of 2)in a texture.
Can someone just correct the code that i have summit above. Thanks in advance