OpenGL报错pixel format with necessary capabilities not found
#include<GLTools.h>
#include<GLShaderManager.h>
#include<GL/glut.h>
int g_width = 800;
int g_height = 600;
int nStep = 200;
const GLfloat a = 0.6f, b = 0.3f;
const GLfloat Pi = 3.1415926536f;
GLShaderManager shaderManager;
GLBatch pointBatch;
GLBatch lineBatch;
GLBatch lineStripBatch;
GLBatch lineLoopBatch;
GLBatch triangleBatch;
GLBatch triangleStripBatch;
GLBatch triangleFanBatch;
void initialize();
void uninitialize();
void display_func(void);
void reshape_func(int w, int h);
void key_func(unsigned char key, int x, int y);
void idle_func();
void initialize()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glClearDepth(1.0);
shaderManager.InitializeStockShaders();
GLfloat vCoast[24][3] = { {2.80,1.20,0.0},{2.0,1.20,0.0},
{2.0,1.08,0.0},{2.0,1.08,0.0},
{0.0,0.80,0.0},{-.40,0.40,0.0},
{-.48,0.2,0.0},{-.40,0.0,0.0},
{-.60,-.40,0.0},{-.80,-.80,0.0},
{-.80,-1.4,0.0},{-.40,-1.60,0.0},
{0.0,-1.20,0.0},{.2,-.80,0.0},
{.48,-.40,0.0},{.2,-.80,0.0},
{.48,.20,0.0},{.80,.40,0.0},
{1.20,.80,0.0},{1.60,.60,0.0},
{2.0,.60,0.0},{2.2,.80,0.0},
{2.40,1.0,0.0},{2.80,1.0,0.0}
};
for (int i = 0; i < 24; i++)
{
vCoast[i][0] *= 0.3;
vCoast[i][1] *= 0.3;
vCoast[i][2] *= 0.3;
}
//Load point batch
pointBatch.Begin(GL_POINT, 24);
pointBatch.CopyVertexData3f(vCoast);
pointBatch.End();
//Load as a bunch of line segments
lineBatch.Begin(GL_LINES, 24);
lineBatch.CopyVertexData3f(vCoast);
lineBatch.End();
//Load as a single line segment
lineStripBatch.Begin(GL_LINE_STRIP, 24);
lineStripBatch.CopyVertexData3f(vCoast);
lineStripBatch.End();
//Single line,connect first and last points
lineLoopBatch.Begin(GL_LINE_LOOP, 24);
lineLoopBatch.CopyVertexData3f(vCoast);
lineLoopBatch.End();
GLfloat vPyramid[16][3] = {0};
float angle = 0;
int i = 0;
for (; angle < (2.0f*Pi)&&i<16; angle += (Pi / 8.0f),i++)
{
int x = 50.0f*sin(angle);
int y = 50.f*cos(angle);
vPyramid[i][1] = x;
vPyramid[i][2] = y;
vPyramid[i][3] = 0.0f;
}
//Load as a triangle fan
triangleFanBatch.Begin(GL_TRIANGLE_FAN,16);
triangleFanBatch.CopyVertexData3f(vPyramid);
triangleFanBatch.End();
}
void display_func(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void idle_func()
{
glutPostRedisplay();
}
void reshape_func(int w, int h)
{
glViewport(0, 0, w, h);
}
void key_func(unsigned char key, int x, int y)
{
switch (key) {
case 49:
case 50:
glLineWidth(2.0f);
lineStripBatch.Draw();
glLineWidth(1.0f);
break;
case 51:
glLineWidth(2.0f);
lineLoopBatch.Draw();
glLineWidth(1.0f);
break;
case 52:
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
triangleBatch.Draw();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
break;
case 53:
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
triangleFanBatch.Draw();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
break;
case 54:
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
triangleStripBatch.Draw();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitWindowSize(g_width, g_height);
glutInitDisplayMode(GLUT_DEPTH || GLUT_DOUBLE || GLUT_RGB);
glutCreateWindow("MyShapes");
initialize();
GLenum err = glewInit();
if (GLEW_OK != err) {
fprintf(stderr, "GLEW Error: $s\n", glewGetErrorString(err));
return 1;
}
glutDisplayFunc(display_func);
glutReshapeFunc(reshape_func);
glutKeyboardFunc(key_func);
glutIdleFunc(idle_func);
glutMainLoop();
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
for (; angle < (2.0f*Pi)&&i<16; angle += (Pi / 8.0f),i++)
楼主数组使用不当啊