几何尺寸与公差论坛

 找回密码
 注册
查看: 1149|回复: 0

【转帖】sw com addin and depth buffer

[复制链接]
发表于 2009-4-13 14:45:52 | 显示全部楼层 |阅读模式
sw com addin and depth buffer
hi all,
i m writing an addin using sw com addin in vc++.
i am using visual studio 2005.
i am required to read the depth information of the model and store it in an array. but i am receiving an error code that maps to "invalid pixel format" when the finction wglmakecurrent(hdc,hrc) is encountered.
i have been programming with vb n c# throughout ... this is the first time i m working on vc++ an finding it a bit hard to comprehend ...!!
i was wondering if anybody could point me to a link of a code that reads zbuffer data of a model.
thank you all ...!!
abraham
if you dont mind me asking why switch to c++ from c# and vb in the first place? as far as sw is concerned you will gain nothing of benefit.
actually i am working on a code left half way .... by another programmer...who did it in vc++!!
he has included "gl.h" and is using the glreadpixel in conjunction with gl_depth_component to read depth buffer!!
i don't mind rewriting it all over in c# as i feel that will make my life a lot easier... but i didn't find a way of using opengl commands in c#....  .....
personally i would re-write it all yourself instead of rehacking someone elses code. that way not only will it be cleaner but you will have a full understanding of every part of the code, and can also enjoy the fact that the end result is entirely yours.
as for opengl, not sure what you are doing with solidworks if you are using opengl unless you are rendering something yourself, but here are a few good links to get you started using opengl libraries build purely for c#:
thank you very much.. that was very informative...!!!
i have a requirement to read out the depth information of all the pixels and preform some computation on it....
i had a few more queries ....
=========================
1. the existing code has been written by creating a vc++ mfc extention dll. i wanted to know if there in any advantage (performance or otherwise) of choosing that over sw com addin.
2. i have installed sw 2007 sdk and tried to create a c# sw com addin project ... but it fails with the error dialog "error hresult e_fail has been returned from a call to com component" as soon as i press the ok. the same was observed for vb.net too.
but in vc++ the addin project was created successfully. what could have gone wrong?
3. here's a part of the code that i tried in vc++ addin...
m_modeldoc2->graphicsredraw2();
long h;
m_modelview->getviewhwnd(&h);
hwnd hwnd = (h);
hdc hdc = getdc(hwnd);
hglrc hrc = wglcreatecontext(hdc);
if(wglmakecurrent(hdc, hrc) == null)
"failed to make rendering context current"
else
"sucessful"
the code fails at this point... and the error code maps to "invalid pixel format" .... am i going wrong
thank you very much again for all the help you are extending
1. no there won't be any advantage. the only difference is that the dll gets registered in the rot (running object table) and loaded by sw as an add-in, which takes a split second. from that point on the performance is the same, possibly even minutely faster as a sw add-in as it may store a prefetch object for the dll.
2. this is usually the code if the com fails to get a handle to sw, so you are best supplying me with some code so i can look at it. also, debug the project and step through it line by line to see where the error is occuring.
3. that may be failing if again it is an in-process call to getviewhwnd. the best way to check that is to create a macro so it runs in-process and do exactly the same (if you know how to do it in vba), if not create an add-in to run the code. if you still get the error i will look into it further.
2. this is usually the code if the com fails to get a handle to sw, so you are best supplying me with some code so i can look at it. also, debug the project and step through it line by line to see where the error is occuring.
i m getting this error in the create new project dialog itself.
i supply the name of the project and select sw com addin from the template ... and hit ok ... and i get this error immediately "error hresult e_fail has been returned from a call to com component"
the status bas says "error creating project" {note that this happens only in vb n c# and not in vc++}
that may be failing if again it is an in-process call to getviewhwnd. the best way to check that is to create a macro so it runs in-process and do exactly the same (if you know how to do it in vba), if not create an add-in to run the code. if you still get the error i will look into it further.
thank you for the suggestion .. i 'll sure try that out!!
thanks a llot again!!
hi luke,
sorry for the delay on my part.... it was a long week end...!!
1. i have tried everything.. but am not getting anywhere.
2. my objective is to use the sw com addin and be able to obtain the opengl rendering context so that i can read the depth buffer!! cud you please help me out. (without using mfc, if possible and a completely managed coding)
3. i m using vc++ sw com addin anyway.. as the other two are not happening for me as stated in my previous post...
thank you very much .. again!!
abraham
hey!!
i got the solution...
m_modeldoc2->graphicsredraw2();
long h;
m_modelview->getviewhwnd(&h);
hwnd hwnd = (h);
cwindow wh(hwnd);
hdc hdc = getdc(wh.m_hwnd);
hglrc hrc = wglcreatecontext(hdc);
if(wglmakecurrent(hdc, hrc) == null)
"failed to make rendering context current"
else
"sucessful"
adding the "bold faced" statements did the trick.... i think i was not crerating the atl window which was causing undefined behaviour...!!
thanks a lot luke for all the suggestions...!!
abraham!!!
ah yes of course, i didn't spot that ! well done. glad it is all sorted.
ab,
i am just messing around with the hwnd of solidworks and basically capturing its pixels using bitblt. all works fine but when i get the pixels from the following:
swapp.activedoc.activeview.getviewhwnd()
and bitblt it i get an image starting at the position that the model is (if maximised it is top left of the screen below the menus) and if you make the window float it is the top position of its window. however, i actually get the pixels from the background solidworks application, not the model view. so basically i am always getting the grey solidworks logo background image, not the model. have you come across this so far? and how do you get your hwnd compared to my method?
ps i have also looped every hwnd from the swapp.frame.modelwindows and the same result. i think it is probably something to do with the 3d model being rendered on a separate buffer like playing movies are (direct to screen) so bitblt is not getting the pixels.
update. the above ps is not the case as using getdesktopwindow with the sw visible gets the model pixels, so its definately a problem with sw handles or i am doing something wrong.
furthermore, if i draw directly on the hwnd's hdc it draws on the solidworks application background too (after checking it again) so it is definately returning the handle to the sw app not the model.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2025-1-3 10:26 , Processed in 0.036213 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表