Opengl 三角形而不是正方形
我试图使用 opengl 在 xcode 内部创建一个旋转正方形,但由于某种原因我有一个旋转三角形?
我正在 sio2 内部执行此操作,但我不认为这是问题所在。
这是三角形: http://img220.imageshack.us/img220/7051/snapzproxscreensnapz001.png
这是我的代码:
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();
}
Im trying to create a spinning square inside of xcode using opengl but instead for some reason I have a spinning triangle?
I'm doing this inside of sio2 but I dont think this is the problem.
Here is the triangle:
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的两个观点是相同的。因此,您只提供了三个独特的点,因此您有一个三角形。
您缺少的点是 -100.0f,-100.0f,
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,