我要发帖 回复

正式会员

5

主题

40

积分

0

专家分

:

私信
发表时间 : 2012-4-15 14:57:11 | 浏览 : 893    评论 : 2
想用用opengl在vega中画个矩形,但一直显示不了。麻烦班主和大神帮我看看是怎么回事,望指教。贴下代码:谢谢

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>                                       
#include "vg.h"            
#include "pf.h"
#include <GL/gl.h>
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
static void Draw(vgChannel *chan, void *udata )
{
        pfPushIdentMatrix();
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        gluOrtho2D(-1, 1, -1, 1 );
        glMatrixMode( GL_MODELVIEW );
        pfPushIdentMatrix();
        pfPushState();
        glBegin( GL_QUADS );
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f( 1.0f, 0.0f, 0.0f);
glVertex3f( 1.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, 1.0f);
        glEnd( );        
        pfPopMatrix();
        pfPopState ();
}

int main()
{          
        vgChannel * vgChan;      
        vgInitSys();
        vgDefineSys( "vegawin.adf" );            
        vgWindow* win = vgGetWin(0);
        //vgProp( win, VGWIN_WINBORDER, 0 );        
        vgConfigSys();
        vgChan=vgGetChan(0);
        vgAddFunc(vgChan,VGCHAN_POSTDRAW,Draw,NULL);
        while(1) {
                vgSyncFrame();
                vgFrame();
        }
        vgExit(0);
        return 0;
}

最近VR访客

hankern 评论于2012-4-15 16:34:12
我是在channel的notify中画的矩形,供参考
  1. context->pushElements(true);


  2. // need to disable the depth buffer since it's enabled by default
  3. vrDepthTest::Element depthTestElement;
  4. depthTestElement.m_enable = false;
  5. context->setElement(vrDepthTest::Element::Id, &depthTestElement);
  6. // set up an orthographic projection.  In this case we'll just map the
  7. // channel viewport to 0 to 1 both horizontally and vertically.
  8. vrTransform::ElementProjection projectionElement;
  9. projectionElement.makeOrthographic(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);

  10. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
  11. glEnable(GL_BLEND);
  12. int width, height;
  13. float hfov, vfov, aspect;
  14. vpWindow *window = *vpWindow::begin();
  15. assert(window);
  16. window->getSize(&width, &height);
  17. channel->getFOVSymmetric(&hfov, &vfov);
  18. if (width > height)
  19.         aspect = (float) width / (float) height;
  20. else aspect = (float) height / (float) width;
  21. vfov = hfov / aspect;

  22. // draw a box around what the binoculars are looking at.  We'll
  23. // compute the size of the box by computing the ratio between the
  24. // main and binocular fields of view.
  25. float x = 0.2;
  26. float y = 0.1;

  27. glColor4f(1.0f, 1.0f, 0.0f, 0.5f);
  28. glBegin(GL_POLYGON);
  29. glVertex2f(-0.7f + -x, 0.7f +  y);
  30. glVertex2f(-0.7f + -x, 0.7f + -y);
  31. glVertex2f(-0.7f +  x, 0.7f + -y);
  32. glVertex2f(-0.7f +  x, 0.7f +  y);
  33. glEnd();

  34. context->setElement(vrTransform::ElementProjection::Id,
  35.         &projectionElement);
  36. context->popElements();
复制代码
我是在channel的notify中画的矩形,供参考
VGLL 评论于2012-4-19 20:37:22
vgConfigSys();
        vgChan=vgGetChan(0);
        vgAddFunc(vgChan,VGCHAN_POSTDRAW,Draw,NULL);
次序?
vgChan=vgGetChan(0);
        vgAddFunc(vgChan,VGCHAN_POSTDRAW,Draw,NULL);
放在
vgConfigSys();前面吧
各类Vega论文、程序、疑难、项目
QQ : 1329460345

手机版|VR开发网 统计 津ICP备18009691号
网安备12019202000257

GMT+8, 2021-1-26 04:03 PM

返回顶部