Skip to content

Commit

Permalink
- Detaching shaders after link
Browse files Browse the repository at this point in the history
- removed deprecated texture2D references
- MacOS compat
- Many getchar()'s to make people read error messages
- A few missing glfwPollEvents()
- Bullet picking bug
  • Loading branch information
Calvin1602 committed Oct 18, 2015
1 parent b740d73 commit 2e24659
Show file tree
Hide file tree
Showing 47 changed files with 166 additions and 30 deletions.
7 changes: 4 additions & 3 deletions common/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path
FragmentShaderStream.close();
}



GLint Result = GL_FALSE;
int InfoLogLength;



// Compile Vertex Shader
printf("Compiling shader : %s\n", vertex_file_path);
char const * VertexSourcePointer = VertexShaderCode.c_str();
Expand Down Expand Up @@ -100,6 +97,10 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path
printf("%s\n", &ProgramErrorMessage[0]);
}


glDetachShader(ProgramID, VertexShaderID);
glDetachShader(ProgramID, FragmentShaderID);

glDeleteShader(VertexShaderID);
glDeleteShader(FragmentShaderID);

Expand Down
5 changes: 5 additions & 0 deletions misc04_building_your_own_app/playground2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ int main( void )
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
return -1;
}

Expand All @@ -38,13 +39,16 @@ int main( void )
if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
{
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
getchar();
glfwTerminate();
return -1;
}

// Initialize GLEW
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}

Expand All @@ -61,6 +65,7 @@ int main( void )

// Swap buffers
glfwSwapBuffers();
glfwPollEvents();

} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
Expand Down
2 changes: 1 addition & 1 deletion misc05_picking/StandardShading.fragmentshader
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main(){
float LightPower = 50.0f;

// Material properties
vec3 MaterialDiffuseColor = texture2D( myTextureSampler, UV ).rgb;
vec3 MaterialDiffuseColor = texture( myTextureSampler, UV ).rgb;
vec3 MaterialAmbientColor = vec3(0.1,0.1,0.1) * MaterialDiffuseColor;
vec3 MaterialSpecularColor = vec3(0.3,0.3,0.3);

Expand Down
10 changes: 7 additions & 3 deletions misc05_picking/misc05_picking_BulletPhysics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ int main( void )
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
return -1;
}

Expand All @@ -102,6 +103,7 @@ int main( void )
window = glfwCreateWindow( 1024, 768, "Misc 05 - Bullet version", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
getchar();
glfwTerminate();
return -1;
}
Expand All @@ -111,6 +113,8 @@ int main( void )
glewExperimental = true; // Needed for core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}

Expand Down Expand Up @@ -314,10 +318,10 @@ int main( void )
out_direction
);

out_direction = out_direction*1000.0f;
glm::vec3 out_end = out_origin + out_direction*1000.0f;

btCollisionWorld::ClosestRayResultCallback RayCallback(btVector3(out_origin.x, out_origin.y, out_origin.z), btVector3(out_direction.x, out_direction.y, out_direction.z));
dynamicsWorld->rayTest(btVector3(out_origin.x, out_origin.y, out_origin.z), btVector3(out_direction.x, out_direction.y, out_direction.z), RayCallback);
btCollisionWorld::ClosestRayResultCallback RayCallback(btVector3(out_origin.x, out_origin.y, out_origin.z), btVector3(out_end.x, out_end.y, out_end.z));
dynamicsWorld->rayTest(btVector3(out_origin.x, out_origin.y, out_origin.z), btVector3(out_end.x, out_end.y, out_end.z), RayCallback);
if(RayCallback.hasHit()) {
std::ostringstream oss;
oss << "mesh " << (size_t)RayCallback.m_collisionObject->getUserPointer();
Expand Down
5 changes: 5 additions & 0 deletions misc05_picking/misc05_picking_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,21 @@ int main( void )
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
return -1;
}

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
window = glfwCreateWindow( 1024, 768, "Misc 05 - version with custom Ray-OBB code", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
getchar();
glfwTerminate();
return -1;
}
Expand All @@ -223,6 +226,8 @@ int main( void )
glewExperimental = true; // Needed for core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}

Expand Down
5 changes: 5 additions & 0 deletions misc05_picking/misc05_picking_slow_easy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ int main( void )
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
return -1;
}

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
window = glfwCreateWindow( 1024, 768, "Misc 05 - Simple but slow version", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
getchar();
glfwTerminate();
return -1;
}
Expand All @@ -54,6 +57,8 @@ int main( void )
glewExperimental = true; // Needed for core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}

Expand Down
5 changes: 5 additions & 0 deletions playground/playground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ int main( void )
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
return -1;
}

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
window = glfwCreateWindow( 1024, 768, "Playground", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
getchar();
glfwTerminate();
return -1;
}
Expand All @@ -36,6 +39,8 @@ int main( void )
// Initialize GLEW
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}

Expand Down
9 changes: 9 additions & 0 deletions tutorial01_first_window/tutorial01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ int main( void )
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
return -1;
}

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
getchar();
glfwTerminate();
return -1;
}
Expand All @@ -39,6 +42,8 @@ int main( void )
// Initialize GLEW
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}

Expand All @@ -49,8 +54,12 @@ int main( void )
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

do{
// Clear the screen. It's not mentioned before Tutorial 02, but it can cause flickering, so it's there nonetheless.
glClear( GL_COLOR_BUFFER_BIT );

// Draw nothing, see you in tutorial 2 !


// Swap buffers
glfwSwapBuffers(window);
glfwPollEvents();
Expand Down
5 changes: 5 additions & 0 deletions tutorial02_red_triangle/tutorial02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ int main( void )
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
return -1;
}

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
window = glfwCreateWindow( 1024, 768, "Tutorial 02 - Red triangle", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
getchar();
glfwTerminate();
return -1;
}
Expand All @@ -42,6 +45,8 @@ int main( void )
glewExperimental = true; // Needed for core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}

Expand Down
7 changes: 6 additions & 1 deletion tutorial03_matrices/tutorial03.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ int main( void )
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
return -1;
}

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL

// Open a window and create its OpenGL context
window = glfwCreateWindow( 1024, 768, "Tutorial 03 - Matrices", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
getchar();
glfwTerminate();
return -1;
}
Expand All @@ -43,6 +46,8 @@ int main( void )
glewExperimental = true; // Needed for core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}

Expand Down
5 changes: 5 additions & 0 deletions tutorial04_colored_cube/tutorial04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ int main( void )
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
return -1;
}

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
window = glfwCreateWindow( 1024, 768, "Tutorial 04 - Colored Cube", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
getchar();
glfwTerminate();
return -1;
}
Expand All @@ -43,6 +46,8 @@ int main( void )
glewExperimental = true; // Needed for core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ uniform sampler2D myTextureSampler;
void main(){

// Output color = color of the texture at the specified UV
color = texture2D( myTextureSampler, UV ).rgb;
color = texture( myTextureSampler, UV ).rgb;
}
1 change: 1 addition & 0 deletions tutorial05_textured_cube/tutorial05.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ int main( void )
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ uniform sampler2D myTextureSampler;
void main(){

// Output color = color of the texture at the specified UV
color = texture2D( myTextureSampler, UV ).rgb;
color = texture( myTextureSampler, UV ).rgb;
}
5 changes: 5 additions & 0 deletions tutorial06_keyboard_and_mouse/tutorial06.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ int main( void )
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
return -1;
}

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
window = glfwCreateWindow( 1024, 768, "Tutorial 0 - Keyboard and Mouse", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
getchar();
glfwTerminate();
return -1;
}
Expand All @@ -45,6 +48,8 @@ int main( void )
glewExperimental = true; // Needed for core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}

Expand Down
Loading

0 comments on commit 2e24659

Please sign in to comment.