简体   繁体   English

Opengl三角形而不是正方形

[英]Opengl Triangle instead of square

Im trying to create a spinning square inside of xcode using opengl but instead for some reason I have a spinning triangle? 我试图使用opengl在xcode中创建一个旋转的正方形,但是由于某种原因,我却有一个旋转的三角形?

I'm doing this inside of sio2 but I dont think this is the problem. 我正在sio2内执行此操作,但我不认为这是问题所在。

Here is the triangle: http://img220.imageshack.us/img220/7051/snapzproxscreensnapz001.png 这是三角形: http : //img220.imageshack.us/img220/7051/snapzproxscreensnapz001.png

Here is my code: 这是我的代码:

void templateRender( void )
{
    const GLfloat squareVertices[] ={
        100.0f, -100.0f,
        100.0f, -100.0f,
        -100.0f, 100.0f,
        100.0f, 100.0f,

    };

    const unsigned char squareColors[] = {
        255, 255, 0, 255,
        0, 255, 255, 255,
        0, 0, 0, 0,
        255, 0, 255, 255,
    };


    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );

    // Your rendering code here...

    sio2WindowEnter2D( sio2->_SIO2window, 0.0f, 1.0f );
    {
        glVertexPointer( 2, GL_FLOAT, 0, squareVertices );
        glEnableClientState(GL_VERTEX_ARRAY);
        //set up the color array
        glColorPointer( 4, GL_UNSIGNED_BYTE, 0, squareColors );
        glEnableClientState( GL_COLOR_ARRAY );

        glTranslatef( sio2->_SIO2window->scl->x * 0.5f,
                     sio2->_SIO2window->scl->y * 0.5f, 0.0f );

        static float rotz = 0.0f;
        glRotatef( rotz, 0.0f, 0.0f, 1.0f );
        rotz += 90.0f * sio2->_SIO2window->d_time;
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    }
    sio2WindowLeave2D();    
}

Two of your points are the same. 您的两个观点是相同的。 Therefore you have only provided three unique points thus you have a triangle. 因此,您仅提供了三个唯一点,因此您有一个三角形。

The point you are missing is -100.0f, -100.0f, 您缺少的点是-100.0f,-100.0f,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 openGL在不同的显示模式下绘制圆形三角形和正方形 - openGL draw circle triangle and square in different display mode 使用OpenGL ES绘制三角形 - Drawing a triangle with OpenGL ES 使用C ++的OpenGL基本三角形渲染不起作用 - OpenGL basic triangle render with c++ not working 在 Swift 中制作按钮三角形而不是矩形的框架 - Making the frame of a button triangle instead of rectangle in Swift OpenGL不会绘制三角形,而是遵循精确格式 - OpenGL won't draw a triangle, followed exact format 错误的转换在OpenGL ES 2(iOS)上渲染简单正方形 - Wrong Transformation Rendering a Simple Square on OpenGL ES 2 (iOS) 想要在矩形棱镜opengl es ios的一面画出正方形 - Want to draw square on one face of a rectangular prism opengl es ios Opengl + C ++需要渲染一个彩色正方形,但是我的代码显示空白屏幕 - Opengl+c++ Need to render a multicolored square but my code is showing blank screen 当UIImagePickerController.allowsEditing = true具有圆形而不是正方形时,是否有一种方法可以使视图调用? - Is there a way to make the view called when UIImagePickerController.allowsEditing = true have a circle instead of square? UIBarButtonItem显示为蓝色正方形而不是我想要的图像(界面编辑器) - UIBarButtonItem showing up as a blue square instead of the image I want (Interface Editor)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM