查看: 1285|回复: 7

画的几个盒子,在不好的显卡的电脑上显示是正确的,但在高级显卡上显示出现了黑色...

[复制链接]

该用户从未签到

发表于 2014-10-24 01:51:33 | 显示全部楼层 |阅读模式
本帖最后由 superwavelet 于 2014-12-6 23:07 编辑

开始就是显示正常的盒子,但是在更好的显卡的机器上每个立方体的每个面上都出现了深色对角线

程序应该没有更改过。

并且盒子的框框的颜色怎么不对,我明显是设置的红色和黄色,怎么看起来像是黑色的?

几个盒子

几个盒子

该用户从未签到

 楼主| 发表于 2014-10-27 04:36:43 | 显示全部楼层
并且盒子的框框的颜色问题解决了。

但是盒子的每个正方形面上还是显示了一条斜线

该用户从未签到

发表于 2014-10-28 23:20:56 | 显示全部楼层
画每个面的方式有问题

该用户从未签到

 楼主| 发表于 2014-11-24 05:10:28 | 显示全部楼层
我发现了,不是代码问题,是硬件的关系。

我把程序换到比较差的显卡的笔记本上,跑起来就没有对角黑线了。

但是如何使得黑线在好显卡的计算机上消失呢?

该用户从未签到

 楼主| 发表于 2014-12-6 23:12:37 | 显示全部楼层
求助各位,还是不知道为什么。画立方体每个面的代码如下:
  1. osg::ref_ptr<osg::Group> drawFilledBox(string name, string point_name, osg::Vec3 min, osg::Vec3 max, osg::Vec4 color, double alpha, bool setDepth, int setDepthNum)
  2. {
  3.         float minX, minY, minZ, maxX, maxY, maxZ;
  4.         if(min.x() <= max.x())
  5.         {
  6.                 minX = min.x();
  7.                 maxX = max.x();
  8.         }
  9.         else
  10.         {
  11.                 minX = max.x();
  12.                 maxX = min.x();
  13.         }
  14.         if(min.z() <= max.z())
  15.         {
  16.                 minZ = min.z();
  17.                 maxZ = max.z();
  18.         }
  19.         else
  20.         {
  21.                 minZ = max.z();
  22.                 maxZ = min.z();
  23.         }
  24.         if(min.y() <= max.y())
  25.         {
  26.                 minY = min.y();
  27.                 maxY = max.y();
  28.         }
  29.         else
  30.         {
  31.                 minY = max.y();
  32.                 maxY = min.y();
  33.         }
  34.         minX = min.x();
  35.         maxX = max.x();
  36.         minZ = min.z();
  37.         maxZ = max.z();
  38.         minY = min.y();
  39.         maxY = max.y();

  40.         osg::Vec3 leftTopNear = osg::Vec3(minX, maxY, minZ);
  41.         osg::Vec3 leftTopFar  = osg::Vec3(minX, maxY, maxZ);
  42.         osg::Vec3 rightTopNear = osg::Vec3(maxX, maxY, minZ);
  43.         osg::Vec3 rightTopFar = osg::Vec3(maxX, maxY, maxZ);
  44.         osg::Vec3 leftBottomNear = osg::Vec3(minX, minY, minZ);
  45.         osg::Vec3 leftBottomFar = osg::Vec3(minX, minY, maxZ);
  46.         osg::Vec3 rightBottomNear = osg::Vec3(maxX, minY, minZ);
  47.         osg::Vec3 rightBottomFar = osg::Vec3(maxX, minY, maxZ);

  48.         osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet(*createStateSet(), osg::CopyOp::SHALLOW_COPY);
  49.         if(setDepth)
  50.                 stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
  51.         else
  52.                 stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);

  53.         stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
  54.         stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF);
  55.         stateset->setMode( GL_POLYGON_SMOOTH, osg::StateAttribute::ON);

  56.         stateset->setRenderBinDetails( setDepthNum, "TraversalOrderBin",
  57.                 osg::StateSet::USE_RENDERBIN_DETAILS );
  58.         stateset->setNestRenderBins(true);

  59.         osg::ref_ptr<osg::CullFace> cull = new osg::CullFace();
  60.         cull->setMode(osg::CullFace::BACK);
  61.         stateset->setAttributeAndModes(cull, osg::StateAttribute::ON);

  62.         osgUtil::SmoothingVisitor sv;
  63. //         geode->accept(sv);
  64. //         geode->setName(name);

  65.         osg::ref_ptr<osg::Geode> geode = new osg::Geode;
  66.         osg::ref_ptr<osg::Geode> geode1 = new osg::Geode;
  67.         osg::ref_ptr<osg::Geode> geode2 = new osg::Geode;
  68.         osg::ref_ptr<osg::Geode> geode3 = new osg::Geode;
  69.         osg::ref_ptr<osg::Geode> geode4 = new osg::Geode;
  70.         osg::ref_ptr<osg::Geode> geode5 = new osg::Geode;
  71.         osg::ref_ptr<osg::Geode> geode6 = new osg::Geode;

  72.         osg::ref_ptr<osg::Geometry> gem = new osg::Geometry;
  73.         osg::ref_ptr<osg::Geometry> gem1 = new osg::Geometry;
  74.         osg::ref_ptr<osg::Geometry> gem2 = new osg::Geometry;
  75.         osg::ref_ptr<osg::Geometry> gem3 = new osg::Geometry;
  76.         osg::ref_ptr<osg::Geometry> gem4 = new osg::Geometry;
  77.         osg::ref_ptr<osg::Geometry> gem5 = new osg::Geometry;
  78.         osg::ref_ptr<osg::Geometry> gem6 = new osg::Geometry;

  79.         osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
  80.         osg::ref_ptr<osg::Vec3Array> vertices1 = new osg::Vec3Array;
  81.         osg::ref_ptr<osg::Vec3Array> vertices2 = new osg::Vec3Array;
  82.         osg::ref_ptr<osg::Vec3Array> vertices3 = new osg::Vec3Array;
  83.         osg::ref_ptr<osg::Vec3Array> vertices4 = new osg::Vec3Array;
  84.         osg::ref_ptr<osg::Vec3Array> vertices5 = new osg::Vec3Array;
  85.         osg::ref_ptr<osg::Vec3Array> vertices6 = new osg::Vec3Array;

  86.         //points
  87.         vertices->push_back(leftTopNear);
  88.         vertices->push_back(leftTopFar);
  89.         vertices->push_back(rightTopFar);
  90.         vertices->push_back(rightTopNear);
  91.         vertices->push_back(leftBottomFar);
  92.         vertices->push_back(leftBottomNear);
  93.         vertices->push_back(rightBottomNear);
  94.         vertices->push_back(rightBottomFar);
  95.         osg::ref_ptr<osg::DrawArrays> da = new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, vertices->size());
  96.         // top

  97.         vertices1->push_back(leftTopNear);
  98.         vertices1->push_back(leftTopFar);
  99.         vertices1->push_back(rightTopFar);
  100.         vertices1->push_back(rightTopNear);

  101.         osg::DrawElementsUInt* topBox = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
  102.         topBox->push_back(0);
  103.         topBox->push_back(1);
  104.         topBox->push_back(2);
  105.         topBox->push_back(3);

  106.         topBox->setName("top");
  107.         //left
  108.         vertices2->push_back(leftBottomFar);
  109.         vertices2->push_back(leftTopFar);
  110.         vertices2->push_back(leftTopNear);
  111.         vertices2->push_back(leftBottomNear);

  112.         osg::DrawElementsUInt* leftBox = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
  113.         leftBox->push_back(0);
  114.         leftBox->push_back(1);
  115.         leftBox->push_back(2);
  116.         leftBox->push_back(3);

  117.         leftBox->setName("left");
  118.         //right
  119.         vertices3->push_back(rightTopFar);
  120.         vertices3->push_back(rightBottomFar);
  121.         vertices3->push_back(rightBottomNear);
  122.         vertices3->push_back(rightTopNear);

  123.         osg::DrawElementsUInt* rightBox = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
  124.         rightBox->push_back(0);
  125.         rightBox->push_back(1);
  126.         rightBox->push_back(2);
  127.         rightBox->push_back(3);

  128.         leftBox->setName("right");
  129.         //Far
  130.         vertices4->push_back(rightBottomFar);
  131.         vertices4->push_back(rightTopFar);
  132.         vertices4->push_back(leftTopFar);
  133.         vertices4->push_back(leftBottomFar);


  134.         osg::DrawElementsUInt* farBox = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
  135.         farBox->push_back(0);
  136.         farBox->push_back(1);
  137.         farBox->push_back(2);
  138.         farBox->push_back(3);

  139.         leftBox->setName("far");

  140.         //Near
  141.         vertices5->push_back(leftTopNear);
  142.         vertices5->push_back(rightTopNear);
  143.         vertices5->push_back(rightBottomNear);
  144.         vertices5->push_back(leftBottomNear);
  145.        
  146.         osg::DrawElementsUInt* nearBox = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
  147.         nearBox->push_back(0);
  148.         nearBox->push_back(1);
  149.         nearBox->push_back(2);
  150.         nearBox->push_back(3);

  151.         nearBox->setName("near");
  152.         //Bottom
  153.         vertices6->push_back(leftBottomFar);
  154.         vertices6->push_back(leftBottomNear);
  155.         vertices6->push_back(rightBottomNear);
  156.         vertices6->push_back(rightBottomFar);

  157.         osg::DrawElementsUInt* bottomBox = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
  158.         bottomBox->push_back(0);
  159.         bottomBox->push_back(1);
  160.         bottomBox->push_back(2);
  161.         bottomBox->push_back(3);

  162.         bottomBox->setName("bottom");

  163.         osg::ref_ptr<osg::Vec4Array> colorArray = new osg::Vec4Array;
  164.         osg::ref_ptr<osg::Vec4Array> colorArray1 = new osg::Vec4Array;
  165.         osg::ref_ptr<osg::Vec4Array> colorArray2 = new osg::Vec4Array;
  166.         osg::ref_ptr<osg::Vec4Array> colorArray3 = new osg::Vec4Array;
  167.         osg::ref_ptr<osg::Vec4Array> colorArray4 = new osg::Vec4Array;
  168.         osg::ref_ptr<osg::Vec4Array> colorArray5 = new osg::Vec4Array;
  169.         osg::ref_ptr<osg::Vec4Array> colorArray6 = new osg::Vec4Array;
  170.         colorArray->push_back(osg::Vec4(1,0,0,0.0));
  171.         colorArray1->push_back(osg::Vec4(1,0,0,alpha));
  172.         colorArray2->push_back(osg::Vec4(0,1,0,alpha));
  173.         colorArray3->push_back(osg::Vec4(0,0,1,alpha));
  174.         colorArray4->push_back(osg::Vec4(1,0,1,alpha));
  175.         colorArray5->push_back(osg::Vec4(1,1,0,alpha));
  176.         colorArray6->push_back(osg::Vec4(0,1,1,alpha));

  177.         gem->addPrimitiveSet(da);
  178.         gem1->addPrimitiveSet(topBox);
  179.         gem2->addPrimitiveSet(leftBox);
  180.         gem3->addPrimitiveSet(rightBox);
  181.         gem4->addPrimitiveSet(farBox);
  182.         gem5->addPrimitiveSet(nearBox);
  183.         gem6->addPrimitiveSet(bottomBox);

  184.         gem->setVertexArray(vertices);
  185.         gem1->setVertexArray(vertices1);
  186.         gem2->setVertexArray(vertices2);
  187.         gem3->setVertexArray(vertices3);
  188.         gem4->setVertexArray(vertices4);
  189.         gem5->setVertexArray(vertices5);
  190.         gem6->setVertexArray(vertices6);

  191.         gem->setColorArray(colorArray);
  192.         gem1->setColorArray(colorArray1);
  193.         gem2->setColorArray(colorArray2);
  194.         gem3->setColorArray(colorArray3);
  195.         gem4->setColorArray(colorArray4);
  196.         gem5->setColorArray(colorArray5);
  197.         gem6->setColorArray(colorArray6);

  198.         gem->setColorBinding(osg::Geometry::BIND_OVERALL);
  199.         gem1->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
  200.         gem2->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
  201.         gem3->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
  202.         gem4->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
  203.         gem5->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
  204.         gem6->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);

  205.         geode->addDrawable(gem);
  206.         geode1->addDrawable(gem1);
  207.         geode2->addDrawable(gem2);
  208.         geode3->addDrawable(gem3);
  209.         geode4->addDrawable(gem4);
  210.         geode5->addDrawable(gem5);
  211.         geode6->addDrawable(gem6);

  212.         geode->setName(point_name);
  213.         geode1->setName("top");
  214.         geode2->setName("left");
  215.         geode3->setName("right");
  216.         geode4->setName("far");
  217.         geode5->setName("near");
  218.         geode6->setName("bottom");

  219.         osg::ref_ptr<Group> group = new osg::Group;
  220.         group->addChild(geode);
  221.         group->addChild(geode1);
  222.         group->addChild(geode2);
  223.         group->addChild(geode3);
  224.         group->addChild(geode4);
  225.         group->addChild(geode5);
  226.         group->addChild(geode6);

  227.         group->setStateSet(stateset);

  228.         return group;
  229. }
复制代码

该用户从未签到

 楼主| 发表于 2015-8-8 22:31:28 | 显示全部楼层
还是不知道为什么

该用户从未签到

发表于 2015-8-15 10:53:39 | 显示全部楼层
二货你开启了多边形平滑,不要开就没问题

该用户从未签到

 楼主| 发表于 2015-8-18 04:35:13 | 显示全部楼层
sky11811 发表于 2015-8-15 10:53
二货你开启了多边形平滑,不要开就没问题

果然没有了,多谢帮主
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表