环境:opengl不知道第几版的,visual studio 2010,windows7,glutdlls37beta
方法:
1、将share目录下的GLee.h, GLee.c, gltools.cpp, gltools.h, math3d.cpp, math3d.h, wglext.h, glut.h拷贝到C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl目录下。
修改math3d.cpp文件第7行:#include "math3d.h"改为#include <gl\math3d.h>
不知道干什么的,但不加入会提示一些无法编译的错误
参考http://hi.baidu.com/deyaliu/blog/item/4261da323bc10acda3cc2b8f.html
在一些include里使用了实际的路径是很不好的,但暂时只找到了这一个可以运行这个示例的方法
方法:
1、将share目录下的GLee.h, GLee.c, gltools.cpp, gltools.h, math3d.cpp, math3d.h, wglext.h, glut.h拷贝到C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl目录下。
2、修改GLee.c文件第43行:#include "GLee.h"改为#include <gl\GLee.h>
修改GLee.h文件第58行:#include <GL/gl.h>改为#include #include <gl/gl.h>修改gltools.cpp文件第10、11、75行:#include "gltools.h"改为#include <gl\gltools.h>,#include "math3d.h"改为#include <gl\math3d.h>, #include "wglext.h"改为#include <gl\wglext.h>
修改gltools.h文件第19、22行:#include "glee.h"改为#include <gl\glee.h>, #include "glut.h"改为#include <gl\glut.h>修改math3d.cpp文件第7行:#include "math3d.h"改为#include <gl\math3d.h>
3、修改transformgl.cpp的头文件为
#include <gl\gltools.h>
#include <gl\math3d.h>
#include "C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl\math3d.cpp"
#include "C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl\gltools.cpp"
4、在transformgl.cpp中加入
(###############2011.10.25########
如果加入#include <gl\GLee.h>和#include "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\gl\Glee.c"
则可以不用加入这段代码
###################################)
PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
PFNGLUNIFORM4FARBPROC glUniform4fARB;
PFNGLUNIFORM1IARBPROC glUniform1iARB;
不知道干什么的,但不加入会提示一些无法编译的错误
参考http://hi.baidu.com/deyaliu/blog/item/4261da323bc10acda3cc2b8f.html
##################################################################
/*
file:first_GLSL.c
compile: get glext.h from www.opengl.org,then type
gcc -D_STDCALL_SUPPORTED first_GLSL.c -lopengl32 -lglut32
*/
#include<stdlib.h>//exit
#include<stdio.h>//printf
#include<GL/glut.h>
#include<windows.h>//wgeGetProcAddress
#include "glext.h" //for the following strings
PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
PFNGLUNIFORM4FARBPROC glUniform4fARB;
PFNGLUNIFORM1IARBPROC glUniform1iARB;
int install_func();//make above function pointers concrete
static const char *FragSource = {
"void main(void)"
"{"
" gl_FragColor = vec4(0.0,1.0,0.0,1.0);"
"}"
};
static const char *VertSource = {
"void main(void)"
"{"
"vec4 a = gl_Vertex;"
"a.x = a.x * 0.5;"
"a.y = a.y * 0.5;"
"gl_Position = gl_ModelViewProjectionMatrix * a;"
"}"
};
GLint program_object,fragment_shader,vertex_shader;
int shader_init()
{
GLint success;
char info[4096];
install_func();
program_object = glCreateProgramObjectARB();
fragment_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
vertex_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
glShaderSourceARB(fragment_shader,1,&FragSource,NULL);
glShaderSourceARB(vertex_shader,1,&VertSource,NULL);
glCompileShaderARB(fragment_shader);
glGetObjectParameterivARB(fragment_shader,GL_OBJECT_COMPILE_STATUS_ARB,&success);
if(!success)
{
glGetInfoLogARB(fragment_shader,sizeof(info),NULL,info);
printf("fragment compile error:%s\n",info);
exit(1);
}
glCompileShaderARB(vertex_shader);
glGetObjectParameterivARB(vertex_shader,GL_OBJECT_COMPILE_STATUS_ARB,&success);
if(!success)
{
glGetInfoLogARB(vertex_shader,sizeof(info),NULL,info);
printf("vertex compile error:%s\n",info);
exit(3);
}
glAttachObjectARB(program_object,fragment_shader);
glAttachObjectARB(program_object,vertex_shader);
glLinkProgramARB(program_object);
glGetObjectParameterivARB(program_object,GL_OBJECT_LINK_STATUS_ARB,&success);
if(!success)
{
printf("link error\n");
exit(2);
}
return 0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glUseProgramObjectARB(program_object);//enable
glutSolidSphere(0.2,32,32);//green
glColor3f(1,0,0);//change color
glRectf(-0.5,-0.5,0.5,-0.3);//still green
glUseProgramObjectARB(0);//disable
glRectf(-0.5,0.3,0.5,0.5);//red
glFlush();
}
int main()
{
glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE);
glutInitWindowSize(400,300);
glutCreateWindow("first GLSL");
glutDisplayFunc(display);
shader_init();
glutMainLoop();
return 0;
}
/*********fixed*************/
int install_func()
{
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)wglGetProcAddress("glCreateProgramObjectARB");
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)wglGetProcAddress("glDeleteObjectARB");
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)wglGetProcAddress("glUseProgramObjectARB");
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)wglGetProcAddress("glCreateShaderObjectARB");
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)wglGetProcAddress("glShaderSourceARB");
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)wglGetProcAddress("glCompileShaderARB");
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)wglGetProcAddress("glGetObjectParameterivARB");
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)wglGetProcAddress("glAttachObjectARB");
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)wglGetProcAddress("glGetInfoLogARB");
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)wglGetProcAddress("glLinkProgramARB");
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)wglGetProcAddress("glGetUniformLocationARB");
glUniform4fARB = (PFNGLUNIFORM4FARBPROC)wglGetProcAddress("glUniform4fARB");
glUniform1iARB = (PFNGLUNIFORM1IARBPROC)wglGetProcAddress("glUniform1iARB");
return !glCreateProgramObjectARB || !glDeleteObjectARB || !glUseProgramObjectARB ||
!glCreateShaderObjectARB || !glCreateShaderObjectARB || !glCompileShaderARB ||
!glGetObjectParameterivARB || !glAttachObjectARB || !glGetInfoLogARB ||
!glLinkProgramARB || !glGetUniformLocationARB || !glUniform4fARB ||
!glUniform1iARB;
}
#######################################################
在一些include里使用了实际的路径是很不好的,但暂时只找到了这一个可以运行这个示例的方法