opengl版本支持和shader支持判断

#include <GL/glew.h>
#include <GL/glut.h> 
#include <stdio.h>

void renderScene()
{
 // 清除颜色缓存
 glClear(GL_COLOR_BUFFER_BIT);

 const GLfloat vertices[3][2]={
  {0.0,0.0},
  {50.0,0.0},
  {25.0,50.0}
 };

 // 设置顶点颜色
 glColor3f(1.0,0.0,0.0);
 glBegin(GL_TRIANGLES);
 glVertex2fv(vertices[0]);
 glVertex2fv(vertices[1]);

 glVertex2fv(vertices[2]);
 glEnd();

 glFlush();
}

void myInit()
{
 // 设置清屏颜色为白色
 glClearColor(1.0,1.0,1.0,1.0);

 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluOrtho2D(0.0,50,0.0,50);
 glMatrixMode(GL_MODELVIEW);
}

//主程序入口 
int main(int argc, char* argv[]) 

 // 初始化窗口和opengl之间的交互
 glutInit(&argc,argv); 

 // 初始化显示模式,使用RGB颜色,使用单缓存
 glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);

 // 初始化窗口大小
 glutInitWindowSize(500,500);

 // 初始化窗口位置
 glutInitWindowPosition(200,200);

 // 创建窗口
 glutCreateWindow("draw triangle");

 // 绑定显示回调函数
 glutDisplayFunc(renderScene);

 glewInit();


 if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)  

  printf_s("Ready for GLSL/n");                    

 else {                                   

  printf_s("Not totally ready :( /n");                       

  exit(1);                     

 }              

 if (glewIsSupported("GL_VERSION_2_0"))
  printf("Ready for OpenGL 2.0\n");
 else {
  printf("OpenGL 2.0 not supported\n");
  exit(1);
 }

 myInit();

 glutMainLoop();

 return 0; 
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值