/** * Function for initialization. */ GLUSboolean init(GLUSvoid) { try { RequreExtentions(); // Load the source of the vertex shader. GLUS loader corrupts shaders. // Thats why we do that manually. // std::ifstream vertSourceFile("../main/Vertex.vert"); std::ifstream fragSourceFile("../main/Fragment.frag"); std::string fragSource; std::string vertSource; fragSourceFile.seekg(0, std::ios::end); fragSource.reserve(fragSourceFile.tellg()); fragSourceFile.seekg(0, std::ios::beg); fragSource.assign((std::istreambuf_iterator<char>(fragSourceFile)), std::istreambuf_iterator<char>()); vertSourceFile.seekg(0, std::ios::end); vertSource.reserve(vertSourceFile.tellg()); vertSourceFile.seekg(0, std::ios::beg); vertSource.assign((std::istreambuf_iterator<char>(vertSourceFile)), std::istreambuf_iterator<char>()); const char* tmpVertSource = vertSource.c_str(); const char* tmpFragSource = fragSource.c_str(); if(!glusBuildProgram(&g_program, (const GLUSchar**)&tmpVertSource, 0, 0, 0, (const GLUSchar**)&tmpFragSource)) throw std::runtime_error("shader compilation failed!"); g_pFullScreenQuad = new FullScreenQuad(); // GL init done. Now init some our internal stuff, related to materials, cameras and other // return GLUS_TRUE; } catch(std::runtime_error e) { std::cerr << e.what() << std::endl; exit(-1); } catch(...) { std::cerr << "Unexpected Exception (init)!" << std::endl; exit(-1); } }
/** * Function for initialization. */ GLUSboolean init(GLUSvoid) { GLfloat points[] = { -1.0f, -1.0f, 0.0f, +1.0f, +1.0f, -1.0f, 0.0f, +1.0f, -1.0f, +1.0f, 0.0f, +1.0f, +1.0f, +1.0f, 0.0f, +1.0f }; GLfloat normals[] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }; GLfloat tangents[] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }; GLfloat texCoords[] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; GLuint indices[] = { 0, 1, 2, 1, 3, 2 }; GLuint numberVertices = 4; GLUStgaimage image; GLUStextfile vertexSource; GLUStextfile fragmentSource; numberIndices = 6; // Load the source of the vertex shader. glusLoadTextFile("../src/Example06/Vertex.vs", &vertexSource); // Load the source of the fragment shader. glusLoadTextFile("../src/Example06/Fragment.fs", &fragmentSource); // Build and ... glusBuildProgram(&g_program, (const GLUSchar**) &vertexSource.text, 0, 0, 0, (const GLUSchar**) &fragmentSource.text); // Destroy the text resource glusDestroyTextFile(&vertexSource); // Destroy the text resource glusDestroyTextFile(&fragmentSource); // ToDo: glGenVertexArrays(1, &g_vao); // ToDo: glBindVertexArray(g_vao); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_projectionLocation = glGetUniformLocation(g_program.program, "projectionMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_modelViewLocation = glGetUniformLocation(g_program.program, "modelViewMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_lightDirLocation = glGetUniformLocation(g_program.program, "lightDir"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_textureLocation = glGetUniformLocation(g_program.program, "firstTexture"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_normalMapLocation = glGetUniformLocation(g_program.program, "normalMap"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_vertexLocation = glGetAttribLocation(g_program.program, "vertex"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_normalLocation = glGetAttribLocation(g_program.program, "normal"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_tangentLocation = glGetAttribLocation(g_program.program, "tangent"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_texCoordLocation = glGetAttribLocation(g_program.program, "texCoord"); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, numberVertices * 4 * sizeof(GLfloat), (GLfloat*) points, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, numberVertices * 3 * sizeof(GLfloat), (GLfloat*) normals, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_tangents); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_tangents); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, numberVertices * 3 * sizeof(GLfloat), (GLfloat*) tangents, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_texCoords); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_texCoords); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, numberVertices * 2 * sizeof(GLfloat), (GLfloat*) texCoords, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_indices); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_indices); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ELEMENT_ARRAY_BUFFER, numberIndices * sizeof(GLuint), (GLuint*) indices, GL_STATIC_DRAW); glusLoadTgaImage("rock_color.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/gentextures.html glGenTextures(1, &g_texture); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_2D, g_texture); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_2D, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glusLoadTgaImage("rock_normal.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/gentextures.html glGenTextures(1, &g_normalMap); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_2D, g_normalMap); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_2D, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml glUseProgram(g_program.program); // Calculate the view matrix ... glusLookAtf(g_modelView, 0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniformMatrix4fv(g_modelViewLocation, 1, GL_FALSE, g_modelView); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_vertexLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_normalLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_normalLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_tangents); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_tangentLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_tangentLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_texCoords); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_texCoordLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniform1i(g_textureLocation, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glActiveTexture.xml glActiveTexture( GL_TEXTURE0); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_2D, g_texture); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniform1i(g_normalMapLocation, 1); // http://www.opengl.org/sdk/docs/man/xhtml/glActiveTexture.xml glActiveTexture( GL_TEXTURE1); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_2D, g_normalMap); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/clearcolor.html glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/cleardepth.html glClearDepth(1.0f); //http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/enable.html glEnable( GL_DEPTH_TEST); //http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/enable.html glEnable( GL_CULL_FACE); return GLUS_TRUE; }
/** * Function for initialization. */ GLUSboolean init(GLUSvoid) { GLUSshape sphere; GLUStextfile vertexSource; GLUStextfile geometrySource; GLUStextfile fragmentSource; // Load the source of the vertex shader. glusLoadTextFile("../src/Example09/Vertex.vs", &vertexSource); // Load the source of the geometry shader. glusLoadTextFile("../src/Example09/Geometry.gs", &geometrySource); // Load the source of the fragment shader. glusLoadTextFile("../src/Example09/Fragment.fs", &fragmentSource); // Build and ... glusBuildProgram(&g_program, (const GLUSchar**) &vertexSource.text, 0, 0, (const GLUSchar**) &geometrySource.text, (const GLUSchar**) &fragmentSource.text); // Destroy the text resource glusDestroyTextFile(&vertexSource); // Destroy the text resource glusDestroyTextFile(&geometrySource); // Destroy the text resource glusDestroyTextFile(&fragmentSource); // ToDo: glGenVertexArrays(1, &g_vao); // ToDo: glBindVertexArray(g_vao); glusCreateSpheref(&sphere, 1.0f, 32); numberIndices = sphere.numberIndices; // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_projectionLocation = glGetUniformLocation(g_program.program, "projectionMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_modelViewLocation = glGetUniformLocation(g_program.program, "modelViewMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_vertexLocation = glGetAttribLocation(g_program.program, "vertex"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_normalLocation = glGetAttribLocation(g_program.program, "normal"); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, sphere.numberVertices * 4 * sizeof(GLfloat), (GLfloat*) sphere.vertices, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, sphere.numberVertices * 3 * sizeof(GLfloat), (GLfloat*) sphere.normals, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_indices); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_indices); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ELEMENT_ARRAY_BUFFER, sphere.numberIndices * sizeof(GLuint), (GLuint*) sphere.indices, GL_STATIC_DRAW); glusDestroyShapef(&sphere); // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml glUseProgram(g_program.program); // ... and the view matrix ... glusLookAtf(g_modelView, 0.0f, 0.0f, 6.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniformMatrix4fv(g_modelViewLocation, 1, GL_FALSE, g_modelView); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_vertexLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_normalLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_normalLocation); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/clearcolor.html glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/cleardepth.html glClearDepth(1.0f); //http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/enable.html glEnable( GL_DEPTH_TEST); //http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/enable.html glEnable( GL_CULL_FACE); return GLUS_TRUE; }
/** * Function for initialization. */ GLUSboolean init(GLUSvoid) { // Points of a triangle. GLfloat* points = (GLfloat*)malloc(WATER_PLANE_LENGTH*WATER_PLANE_LENGTH*4*sizeof(GLfloat)); GLuint* indices = (GLuint*)malloc(WATER_PLANE_LENGTH*(WATER_PLANE_LENGTH-1)*2*sizeof(GLuint)); GLUSshape background; GLUStgaimage image; GLUStextfile vertexSource; GLUStextfile fragmentSource; GLuint x, z, i, k; GLuint waterTexture; for (z = 0; z < WATER_PLANE_LENGTH; z++) { for (x = 0; x < WATER_PLANE_LENGTH; x++) { points[(x+z*(WATER_PLANE_LENGTH))*4 + 0] = -(GLfloat)WATER_PLANE_LENGTH/2 + 0.5f + (GLfloat)x; points[(x+z*(WATER_PLANE_LENGTH))*4 + 1] = 0.0f; points[(x+z*(WATER_PLANE_LENGTH))*4 + 2] = +(GLfloat)WATER_PLANE_LENGTH/2 - 0.5f - (GLfloat)z; points[(x+z*(WATER_PLANE_LENGTH))*4 + 3] = 1.0f; } } for (k = 0; k < WATER_PLANE_LENGTH-1; k++) { for (i = 0; i < WATER_PLANE_LENGTH; i++) { if (k%2 == 0) { indices[(i+k*(WATER_PLANE_LENGTH))*2 + 0] = i + k*WATER_PLANE_LENGTH; indices[(i+k*(WATER_PLANE_LENGTH))*2 + 1] = i + (k+1)*WATER_PLANE_LENGTH; } else { indices[(i+k*(WATER_PLANE_LENGTH))*2 + 0] = WATER_PLANE_LENGTH - 1 - i + k*WATER_PLANE_LENGTH; indices[(i+k*(WATER_PLANE_LENGTH))*2 + 1] = WATER_PLANE_LENGTH - 1 - i + (k+1)*WATER_PLANE_LENGTH; } } } // Load the source of the vertex shader. glusLoadTextFile("../src/Example14/Vertex.vs", &vertexSource); // Load the source of the fragment shader. glusLoadTextFile("../src/Example14/Fragment.fs", &fragmentSource); // Build and ... glusBuildProgram(&g_program, (const GLUSchar**) &vertexSource.text, 0, 0, 0, (const GLUSchar**) &fragmentSource.text); // Destroy the text resource glusDestroyTextFile(&vertexSource); // Destroy the text resource glusDestroyTextFile(&fragmentSource); // ToDo: glGenVertexArrays(1, &g_vao); // ToDo: glBindVertexArray(g_vao); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_projectionLocation = glGetUniformLocation(g_program.program, "projectionMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_modelViewLocation = glGetUniformLocation(g_program.program, "modelViewMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_waterPlaneLengthLocation = glGetUniformLocation(g_program.program, "waterPlaneLength"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_inverseCameraLocation = glGetUniformLocation(g_program.program, "inverseCameraMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_cubemapLocation = glGetUniformLocation(g_program.program, "cubemap"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_waterLocation = glGetUniformLocation(g_program.program, "waterTexture"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_passedTimeLocation = glGetUniformLocation(g_program.program, "passedTime"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_waveParametersLocation = glGetUniformLocation(g_program.program, "waveParameters"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_waveDirectionsLocation = glGetUniformLocation(g_program.program, "waveDirections"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_vertexLocation = glGetAttribLocation(g_program.program, "vertex"); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, WATER_PLANE_LENGTH*WATER_PLANE_LENGTH * 4 * sizeof(GLfloat), (GLfloat*) points, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_indices); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_indices); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ELEMENT_ARRAY_BUFFER, WATER_PLANE_LENGTH*(WATER_PLANE_LENGTH-1) * 2 * sizeof(GLuint), (GLuint*) indices, GL_STATIC_DRAW); // free(points); free(indices); // // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/gentextures.html glGenTextures(1, &g_cubemap); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_CUBE_MAP, g_cubemap); glusLoadTgaImage("water_pos_x.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); glusLoadTgaImage("water_neg_x.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); glusLoadTgaImage("water_pos_y.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); glusLoadTgaImage("water_neg_y.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); glusLoadTgaImage("water_pos_z.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); glusLoadTgaImage("water_neg_z.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_CUBE_MAP, 0); // // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml glUseProgram(g_program.program); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniform1f(g_waterPlaneLengthLocation, (GLUSfloat)WATER_PLANE_LENGTH); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_vertexLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glActiveTexture.xml glActiveTexture(GL_TEXTURE0); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_CUBE_MAP, g_cubemap); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniform1i(g_cubemapLocation, 0); // Get the render buffer texture waterTexture = initTexture((GLUSfloat)WATER_PLANE_LENGTH); // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml glUseProgram(g_program.program); // http://www.opengl.org/sdk/docs/man/xhtml/glActiveTexture.xml glActiveTexture(GL_TEXTURE1); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_2D, waterTexture); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniform1i(g_waterLocation, 1); // // Load the source of the vertex shader. glusLoadTextFile("../src/Example14/VertexBackground.vs", &vertexSource); // Load the source of the fragment shader. glusLoadTextFile("../src/Example14/FragmentBackground.fs", &fragmentSource); // Build and ... glusBuildProgram(&g_programBackground, (const GLUSchar**) &vertexSource.text, 0, 0, 0, (const GLUSchar**) &fragmentSource.text); // Destroy the text resource glusDestroyTextFile(&vertexSource); // Destroy the text resource glusDestroyTextFile(&fragmentSource); // ToDo: glGenVertexArrays(1, &g_vaoBackground); // ToDo: glBindVertexArray(g_vaoBackground); glusCreateSpheref(&background, (GLfloat)(GLfloat)WATER_PLANE_LENGTH/2.0f + 0.5f, 32); g_numberIndicesBackground = background.numberIndices; // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_projectionLocationBackground = glGetUniformLocation(g_programBackground.program, "projectionMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_modelViewLocationBackground = glGetUniformLocation(g_programBackground.program, "modelViewMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_cubemapLocationBackground = glGetUniformLocation(g_programBackground.program, "cubemap"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_vertexLocationBackground = glGetAttribLocation(g_programBackground.program, "vertex"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_normalLocationBackground = glGetAttribLocation(g_programBackground.program, "normal"); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_verticesBackground); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_verticesBackground); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, background.numberVertices * 4 * sizeof(GLfloat), (GLfloat*) background.vertices, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_normalsBackground); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_normalsBackground); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, background.numberVertices * 3 * sizeof(GLfloat), (GLfloat*) background.normals, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_indicesBackground); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_indicesBackground); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ELEMENT_ARRAY_BUFFER, background.numberIndices * sizeof(GLuint), (GLuint*) background.indices, GL_STATIC_DRAW); glusDestroyShapef(&background); // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml glUseProgram(g_programBackground.program); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniformMatrix4fv(g_modelViewLocationBackground, 1, GL_FALSE, g_modelView); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_verticesBackground); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_vertexLocationBackground, 4, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_vertexLocationBackground); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_normalsBackground); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_normalLocationBackground, 3, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_normalLocationBackground); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniform1i(g_cubemapLocationBackground, 0); // // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/clearcolor.html glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/cleardepth.html glClearDepth(1.0f); //http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/enable.html glEnable( GL_DEPTH_TEST); return GLUS_TRUE; }
/** * Function for initialization. */ GLUSboolean init(GLUSvoid) { // Points for referencing each texel GLfloat points[PARTICLES_LOOKUP_WIDTH*PARTICLES_LOOKUP_WIDTH*2]; // Initial particle data GLfloat particle[PARTICLES_LOOKUP_WIDTH*PARTICLES_LOOKUP_WIDTH*4]; GLUStgaimage image; GLUStextfile vertexSource; GLUStextfile fragmentSource; GLuint x, y; // Create points which are refernceing on the different texels for (y = 0; y < PARTICLES_LOOKUP_WIDTH; y++) { for (x = 0; x < PARTICLES_LOOKUP_WIDTH; x++) { points[x*2+0 + y*PARTICLES_LOOKUP_WIDTH*2] = (GLfloat)x/(GLfloat)PARTICLES_LOOKUP_WIDTH; points[x*2+1 + y*PARTICLES_LOOKUP_WIDTH*2] = (GLfloat)y/(GLfloat)PARTICLES_LOOKUP_WIDTH; } } // Create the initial particles data for (y = 0; y < PARTICLES_LOOKUP_WIDTH; y++) { for (x = 0; x < PARTICLES_LOOKUP_WIDTH; x++) { particle[x*4+0 + y*PARTICLES_LOOKUP_WIDTH*4] = 0.0f; particle[x*4+1 + y*PARTICLES_LOOKUP_WIDTH*4] = 0.0f; particle[x*4+2 + y*PARTICLES_LOOKUP_WIDTH*4] = 0.0f; particle[x*4+3 + y*PARTICLES_LOOKUP_WIDTH*4] = (rand()%101)/100.0f; } } // Load the source of the vertex shader. glusLoadTextFile("../Example08/Vertex.vs", &vertexSource); // Load the source of the fragment shader. glusLoadTextFile("../Example08/Fragment.fs", &fragmentSource); // Build and ... glusBuildProgram(&g_program, (const GLUSchar**)&vertexSource.text, 0, (const GLUSchar**)&fragmentSource.text); // Destroy the text resource glusDestroyTextFile(&vertexSource); // Destroy the text resource glusDestroyTextFile(&fragmentSource); // ToDo: glGenVertexArrays(1, &g_vao); // ToDo: glBindVertexArray(g_vao); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_projectionLocation = glGetUniformLocation(g_program.program, "projectionMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_modelViewLocation = glGetUniformLocation(g_program.program, "modelViewMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_textureLocation = glGetUniformLocation(g_program.program, "firstTexture"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_lookuptextureLocation = glGetUniformLocation(g_program.program, "readTexture"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_vertexLocation = glGetAttribLocation(g_program.program, "vertex"); // ToDo: glBindFragDataLocation(g_program.program, 0, "fragColor"); // Load the source of the vertex shader. glusLoadTextFile("../Example08/UpdatePoints.vs", &vertexSource); // Load the source of the fragment shader. glusLoadTextFile("../Example08/UpdatePoints.fs", &fragmentSource); // Build and ... glusBuildProgram(&g_programUpdate, (const GLUSchar**)&vertexSource.text, 0, (const GLUSchar**)&fragmentSource.text); // Destroy the text resource glusDestroyTextFile(&vertexSource); // Destroy the text resource glusDestroyTextFile(&fragmentSource); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_lookuptextureLocationUpdate = glGetUniformLocation(g_programUpdate.program, "readTexture"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_sizeLocation = glGetUniformLocation(g_programUpdate.program, "size"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_timeLocation = glGetUniformLocation(g_programUpdate.program, "time"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_vertexLocationUpdate = glGetAttribLocation(g_programUpdate.program, "vertex"); // ToDo: glBindFragDataLocation(g_programUpdate.program, 0, "fragParticle"); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, PARTICLES_LOOKUP_WIDTH*PARTICLES_LOOKUP_WIDTH*2*sizeof(GLfloat), (GLfloat*)points, GL_STATIC_DRAW); glusLoadTgaImage("particle.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/gentextures.html glGenTextures(1, &g_texture); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_2D, g_texture); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_2D, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/gentextures.html glGenTextures(2, g_lookuptexture); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_2D, g_lookuptexture[0]); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, PARTICLES_LOOKUP_WIDTH, PARTICLES_LOOKUP_WIDTH, 0, GL_RGBA, GL_FLOAT, particle); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_2D, g_lookuptexture[1]); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, PARTICLES_LOOKUP_WIDTH, PARTICLES_LOOKUP_WIDTH, 0, GL_RGBA, GL_FLOAT, particle); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // ToDo: glGenFramebuffers(2, g_lookupframebuffer); // ToDo: glBindFramebuffer(GL_FRAMEBUFFER, g_lookupframebuffer[0]); // ToDo: glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, g_lookuptexture[0], 0); // ToDo: glBindFramebuffer(GL_FRAMEBUFFER, g_lookupframebuffer[1]); // ToDo: glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, g_lookuptexture[1], 0); // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml glUseProgram(g_program.program); // Calculate the view matrix ... glusLookAtf(g_modelView, 0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniformMatrix4fv(g_modelViewLocation, 1, GL_FALSE, g_modelView); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_vertexLocation, 2, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_vertexLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniform1i(g_textureLocation, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glActiveTexture.xml glActiveTexture(GL_TEXTURE0); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_2D, g_texture); // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml glUseProgram(g_programUpdate.program); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniform1f(g_sizeLocation, (GLfloat)PARTICLES_LOOKUP_WIDTH); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_vertexLocationUpdate, 2, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_vertexLocationUpdate); // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml glUseProgram(g_program.program); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/clearcolor.html glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/enable.html glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); return GLUS_TRUE; }
/** * Function for initialization. */ GLUSboolean init(GLUSvoid) { // Points of a cube. GLfloat points[] = { -0.5f, -0.5f, -0.5f, 1.0f, -0.5f, -0.5f, +0.5f, 1.0f, +0.5f, -0.5f, +0.5f, 1.0f, +0.5f, -0.5f, -0.5f, 1.0f, -0.5f, +0.5f, -0.5f, 1.0f, -0.5f, +0.5f, +0.5f, 1.0f, +0.5f, +0.5f, +0.5f, 1.0f, +0.5f, +0.5f, -0.5f, 1.0f, -0.5f, -0.5f, -0.5f, 1.0f, -0.5f, +0.5f, -0.5f, 1.0f, +0.5f, +0.5f, -0.5f, 1.0f, +0.5f, -0.5f, -0.5f, 1.0f, -0.5f, -0.5f, +0.5f, 1.0f, -0.5f, +0.5f, +0.5f, 1.0f, +0.5f, +0.5f, +0.5f, 1.0f, +0.5f, -0.5f, +0.5f, 1.0f, -0.5f, -0.5f, -0.5f, 1.0f, -0.5f, -0.5f, +0.5f, 1.0f, -0.5f, +0.5f, +0.5f, 1.0f, -0.5f, +0.5f, -0.5f, 1.0f, +0.5f, -0.5f, -0.5f, 1.0f, +0.5f, -0.5f, +0.5f, 1.0f, +0.5f, +0.5f, +0.5f, 1.0f, +0.5f, +0.5f, -0.5f, 1.0f }; // Normals of a cube. GLfloat normals[] = { +0.0f, -1.0f, +0.0f, +0.0f, -1.0f, +0.0f, +0.0f, -1.0f, +0.0f, +0.0f, -1.0f, +0.0f, +0.0f, +1.0f, +0.0f, +0.0f, +1.0f, +0.0f, +0.0f, +1.0f, +0.0f, +0.0f, +1.0f, +0.0f, +0.0f, +0.0f, -1.0f, +0.0f, +0.0f, -1.0f, +0.0f, +0.0f, -1.0f, +0.0f, +0.0f, -1.0f, +0.0f, +0.0f, +1.0f, +0.0f, +0.0f, +1.0f, +0.0f, +0.0f, +1.0f, +0.0f, +0.0f, +1.0f, -1.0f, +0.0f, +0.0f, -1.0f, +0.0f, +0.0f, -1.0f, +0.0f, +0.0f, -1.0f, +0.0f, +0.0f, +1.0f, +0.0f, +0.0f, +1.0f, +0.0f, +0.0f, +1.0f, +0.0f, +0.0f, +1.0f, +0.0f, +0.0f }; // The associated indices. GLuint indices[] = { 0, 2, 1, 0, 3, 2, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 15, 14, 12, 14, 13, 16, 17, 18, 16, 18, 19, 20, 23, 22, 20, 22, 21 }; GLUStgaimage image; GLUStextfile vertexSource; GLUStextfile fragmentSource; // Load the source of the vertex shader. glusLoadTextFile("../src/Example07/Vertex.vs", &vertexSource); // Load the source of the fragment shader. glusLoadTextFile("../src/Example07/Fragment.fs", &fragmentSource); // Build and ... glusBuildProgram(&g_program, (const GLUSchar**) &vertexSource.text, 0, 0, 0, (const GLUSchar**) &fragmentSource.text); // Destroy the text resource glusDestroyTextFile(&vertexSource); // Destroy the text resource glusDestroyTextFile(&fragmentSource); // ToDo: glGenVertexArrays(1, &g_vao); // ToDo: glBindVertexArray(g_vao); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_projectionLocation = glGetUniformLocation(g_program.program, "projectionMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_modelViewLocation = glGetUniformLocation(g_program.program, "modelViewMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_inverseCameraLocation = glGetUniformLocation(g_program.program, "inverseCameraMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_cubemapLocation = glGetUniformLocation(g_program.program, "cubemap"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_vertexLocation = glGetAttribLocation(g_program.program, "vertex"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_normalLocation = glGetAttribLocation(g_program.program, "normal"); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, 24 * 4 * sizeof(GLfloat), (GLfloat*) points, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, 24 * 3 * sizeof(GLfloat), (GLfloat*) normals, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_indices); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_indices); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * 2 * 3 * sizeof(GLuint), (GLuint*) indices, GL_STATIC_DRAW); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/gentextures.html glGenTextures(1, &g_cubemap); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_CUBE_MAP, g_cubemap); glusLoadTgaImage("cm_left.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); glusLoadTgaImage("cm_right.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); glusLoadTgaImage("cm_top.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); glusLoadTgaImage("cm_bottom.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); glusLoadTgaImage("cm_back.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); glusLoadTgaImage("cm_front.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT); // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml glUseProgram(g_program.program); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_vertexLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_normalLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_normalLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniform1i(g_cubemapLocation, 0); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/clearcolor.html glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/cleardepth.html glClearDepth(1.0f); //http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/enable.html glEnable( GL_DEPTH_TEST); //http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/enable.html glEnable( GL_CULL_FACE); return GLUS_TRUE; }
/** * Function for initialization. */ GLUSboolean init(GLUSvoid) { // Matrix for the model GLfloat model[16]; GLUSshape cube; GLUStgaimage image; GLUStextfile vertexSource; GLUStextfile fragmentSource; // Load the source of the vertex shader. glusLoadTextFile("../Example05/Vertex.vs", &vertexSource); // Load the source of the fragment shader. glusLoadTextFile("../Example05/Fragment.fs", &fragmentSource); // Build and ... glusBuildProgram(&g_program, (const GLUSchar**)&vertexSource.text, 0, (const GLUSchar**)&fragmentSource.text); // Destroy the text resource glusDestroyTextFile(&vertexSource); // Destroy the text resource glusDestroyTextFile(&fragmentSource); // ToDo: glGenVertexArrays(1, &g_vao); // ToDo: glBindVertexArray(g_vao); glusCreateCubef(&cube, 0.5f); numberIndices = cube.numberIndices; // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_projectionLocation = glGetUniformLocation(g_program.program, "projectionMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_modelViewLocation = glGetUniformLocation(g_program.program, "modelViewMatrix"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml g_textureLocation = glGetUniformLocation(g_program.program, "firstTexture"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_vertexLocation = glGetAttribLocation(g_program.program, "vertex"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_normalLocation = glGetAttribLocation(g_program.program, "normal"); // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml g_texCoordLocation = glGetAttribLocation(g_program.program, "texCoord"); // ToDo: glBindFragDataLocation(g_program.program, 0, "fragColor"); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, cube.numberVertices*4*sizeof(GLfloat), (GLfloat*)cube.vertices, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, cube.numberVertices*3*sizeof(GLfloat), (GLfloat*)cube.normals, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_texCoords); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_texCoords); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ARRAY_BUFFER, cube.numberVertices*2*sizeof(GLfloat), (GLfloat*)cube.texCoords, GL_STATIC_DRAW); // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml glGenBuffers(1, &g_indices); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_indices); // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml glBufferData(GL_ELEMENT_ARRAY_BUFFER, cube.numberIndices*sizeof(GLuint), (GLuint*)cube.indices, GL_STATIC_DRAW); glusDestroyShapef(&cube); glusLoadTgaImage("crate.tga", &image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/gentextures.html glGenTextures(1, &g_texture); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/bindtexture.html glBindTexture(GL_TEXTURE_2D, g_texture); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html glTexImage2D(GL_TEXTURE_2D, 0, image.format, image.width, image.height, 0, image.format, GL_UNSIGNED_BYTE, image.data); glusDestroyTgaImage(&image); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texparameter.html glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml glUseProgram(g_program.program); // Calculate the model matrix ... glusLoadIdentityf(model); glusRotateRzRyRxf(model, 30.0f, 30.0f, 0.0f); // ... and the view matrix ... glusLookAtf(g_modelView, 0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); // ... to get the final model view matrix glusMultMatrixf(g_modelView, g_modelView, model); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniformMatrix4fv(g_modelViewLocation, 1, GL_FALSE, g_modelView); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_vertices); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_vertexLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_normals); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_normalLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_normalLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml glBindBuffer(GL_ARRAY_BUFFER, g_texCoords); // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml glVertexAttribPointer(g_texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, 0); // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml glEnableVertexAttribArray(g_texCoordLocation); // http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml glUniform1i(g_textureLocation, 0); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/clearcolor.html glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/cleardepth.html glClearDepth(1.0f); //http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/enable.html glEnable(GL_DEPTH_TEST); //http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/enable.html glEnable(GL_CULL_FACE); return GLUS_TRUE; }