// rendering context initialization void SetupRC(){ shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); glClearColor(r, g, b, 1.0f); gltMakeCube(cubeBatch, .1f); GLfloat x, y; // TODO - enable realtime switching between these (and more) for(int i = 0; i < PACKET_SIZE; i++){ if(mapper.getCompoundArg('s') == "circle"){ x = sin(i * .1); y = cos(i * .1); } else if(mapper.getCompoundArg('s') == "wave"){ x = -(PACKET_SIZE * .5 * barWidth * .2) + i * barWidth * .2; y = cos(i * .1); } else{ x = -(PACKET_SIZE * .5 * barWidth * .2) + i * barWidth * .2; y = 0; } bars[i].SetOrigin(x, y, -3.0f); } for(int i = 0; i < NUM_MACROS; i++){ // TODO - parameterize this spacing macros[i].refFrame.SetOrigin((rand() % 20) - 10, (rand() % 20) - 10, (rand() % 10) - 20); //macros[i].refFrame.RotateLocalZ(i*5); macros[i].multiplier = rand() % 10; } }
////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering // context. void SetupRC() { GLbyte *pBytes; GLint iWidth, iHeight, iComponents; GLenum eFormat; int i; // Cull backs of polygons glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_DEPTH_TEST); glGenTextures(1, &cubeTexture); glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTexture); // Set up texture maps glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Load Cube Map images for(i = 0; i < 6; i++) { // Load this texture map pBytes = gltReadTGABits(szCubeFaces[i], &iWidth, &iHeight, &iComponents, &eFormat); glTexImage2D(cube[i], 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytes); free(pBytes); } glGenerateMipmap(GL_TEXTURE_CUBE_MAP); viewFrame.MoveForward(-4.0f); gltMakeSphere(sphereBatch, 1.0f, 52, 26); gltMakeCube(cubeBatch, 20.0f); reflectionShader = gltLoadShaderPairWithAttributes("Reflection.vp", "Reflection.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locMVPReflect = glGetUniformLocation(reflectionShader, "mvpMatrix"); locMVReflect = glGetUniformLocation(reflectionShader, "mvMatrix"); locNormalReflect = glGetUniformLocation(reflectionShader, "normalMatrix"); locInvertedCamera = glGetUniformLocation(reflectionShader, "mInverseCamera"); skyBoxShader = gltLoadShaderPairWithAttributes("SkyBox.vp", "SkyBox.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locMVPSkyBox = glGetUniformLocation(skyBoxShader, "mvpMatrix"); }
const int CubeMap::Initialize( Context* ctx ) { // Variable for looping int i; // Set the cube map in texture unit 1 glActiveTexture( GL_TEXTURE0 + 1 ); glGenTextures(1, &textureFile); glBindTexture(GL_TEXTURE_CUBE_MAP, textureFile); /* Set up texture maps */ glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* Load Cube Map Images */ for( i = 0; i < 6; i++ ) { // Load this texture map pBytes = gltReadTGABits(szCubeFaces[i], &iWidth, &iHeight, &iComponents, &eFormat); glTexImage2D( cube[i], 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytes ); free(pBytes); } glGenerateMipmap( GL_TEXTURE_CUBE_MAP ); gltMakeCube( batch, cubeMapSize ); shaderFile = ctx->shaderManager->LoadShaderPairWithAttributes( "./../shaders/SkyBox.vp", "./../shaders/SkyBox.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal" ); locMVPSkyBox = glGetUniformLocation(shaderFile, "mvpMatrix"); locCubeMap = glGetUniformLocation(shaderFile, "cubeMap"); // Revert to texture unit 0 glActiveTexture( GL_TEXTURE0 ); return SHR_SUCCESS; }
void SetupRC() { glClearColor(0, 0, 0, 1); shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); gltMakeSphere(sphereBatch, 0.4, 20, 20); gltMakeCube(cubeBatch, 0.3); // Load up a triangle GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f }; GLfloat vColors [] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f }; triangleBatch.Begin(GL_TRIANGLES, 3); triangleBatch.CopyVertexData3f(vVerts); triangleBatch.CopyColorData4f(vColors); triangleBatch.End(); mWcgCube.SetupCube(); /*transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);*/ cameraFrame.MoveForward(-3.0f); m3dLoadIdentity44(mRotation); myShader = gltLoadShaderPairWithAttributes("shader.vp", "shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_COLOR, "vColor"); locMVP = glGetUniformLocation(myShader, "mvpMatrix"); }
// ///////////////////////////////////////////////////////////////// // // ///////////////////////////////////////////////////////////////// void EnvironmentSceneNode::Init(const std::vector<std::string> &cubemapTextureNameVec, const std::string &shaderNameRef, const F32 cmRadius) throw(GameException &) { // Load the textures for the sides of the cubemap. boost::optional<TexHandle> tHandle = g_appPtr->GetTextureManagerPtr()->LoadCubeMap(cubemapTextureNameVec, GL_CLAMP_TO_EDGE); if(!tHandle.is_initialized()) { throw GameException(std::string("Failed to load the textures for the EnvironmentMap")); } m_texHandle = *tHandle; SceneNode::SetRadius(cmRadius); // TODO: Remove dependancy on GLTools external lib. gltMakeCube(m_cubeBatch, cmRadius); // Set the shader name (The SGM should already have this shader built and included). SceneNode::SetShaderName(shaderNameRef); if(m_shaderPtr) { m_mvpUniform = m_shaderPtr->GetUniform("mvpMatrix"); m_cmUniform = m_shaderPtr->GetUniform("cubeMap"); } }
bool App::Load() { // force size and vsync SetSize(SCREEN_WIDTH, SCREEN_HEIGHT); SetVSync(true); // set up basic OpenGL parameters GL_DEBUG(glClearColor(0.3f, 0.3f, 0.3f, 1.0f)); GL_DEBUG(glEnable(GL_DEPTH_TEST)); // load textures cubeTexture = g_Texture.LoadTexture("crate.png"); baseTexture = g_Texture.LoadTexture("concrete2.jpg", true); // load shaders phongShader = g_Shader.CreateProgram("texPhong.vert", "texPhong.frag", 3, FF_ATTRIBUTE_VERTEX, "vVertex", FF_ATTRIBUTE_NORMAL, "vNormal", FF_ATTRIBUTE_TEXTURE0, "vTexture0"); blurShader = g_Shader.CreateProgram("blur.vert", "blur.frag", 2, FF_ATTRIBUTE_VERTEX, "vVertex", FF_ATTRIBUTE_TEXTURE0, "vTexture0"); // get locations for shader uniforms locTexture = GL_DEBUG(glGetUniformLocation(phongShader, "texSampler")); locLightPos = GL_DEBUG(glGetUniformLocation(phongShader, "lightPos")); locMV = GL_DEBUG(glGetUniformLocation(phongShader, "mvMatrix")); locMVP = GL_DEBUG(glGetUniformLocation(phongShader, "mvpMatrix")); locNM = GL_DEBUG(glGetUniformLocation(phongShader, "normalMatrix")); locAmbient = GL_DEBUG(glGetUniformLocation(phongShader, "ambient")); locDiffuse = GL_DEBUG(glGetUniformLocation(phongShader, "diffuse")); locSpecular = GL_DEBUG(glGetUniformLocation(phongShader, "specular")); locBlurMVP = GL_DEBUG(glGetUniformLocation(blurShader, "mvpMatrix")); // create geometry gltMakeCube(cube, 1); screen.Begin(GL_TRIANGLE_STRIP, 4, 1); screen.MultiTexCoord2f(0, 0, 0); screen.Vertex3f(0, 0, 0); screen.MultiTexCoord2f(0, 1, 0); screen.Vertex3f((float)GetWidth(), 0, 0); screen.MultiTexCoord2f(0, 0, 1); screen.Vertex3f(0, (float)GetHeight(), 0); screen.MultiTexCoord2f(0, 1, 1); screen.Vertex3f((float)GetWidth(), (float)GetHeight(), 0); screen.End(); const float baseSize = 40.0f; const float baseHeight = -3.f; base.Begin(GL_TRIANGLE_STRIP, 8, 1); base.MultiTexCoord2f(0, 0, 0); base.Vertex3f(-baseSize, baseHeight, baseSize); base.MultiTexCoord2f(0, baseSize, 0); base.Vertex3f(baseSize, baseHeight, baseSize); base.MultiTexCoord2f(0, 0, baseSize); base.Vertex3f(-baseSize, baseHeight, -baseSize); base.MultiTexCoord2f(0, baseSize, baseSize); base.Vertex3f(baseSize, baseHeight, -baseSize); base.MultiTexCoord2f(0, 0, 0); base.Vertex3f(-baseSize, baseHeight, -baseSize); base.MultiTexCoord2f(0, baseSize, 0); base.Vertex3f(baseSize, baseHeight, -baseSize); base.MultiTexCoord2f(0, 0, baseSize); base.Vertex3f(-baseSize, baseHeight + baseSize, -baseSize); base.MultiTexCoord2f(0, baseSize, baseSize); base.Vertex3f(baseSize, baseHeight + baseSize, -baseSize); base.End(); // create pixel buffer glGenBuffers(1, &pbo); glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); glBufferData(GL_PIXEL_PACK_BUFFER, PIXEL_DATA_SIZE, NULL, GL_DYNAMIC_DRAW); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); // create blur textures glGenTextures(BLUR_TEXTURE_COUNT, blurTextures); for (int i = 0; i < BLUR_TEXTURE_COUNT; ++i) { glActiveTexture(GL_TEXTURE1 + i); glBindTexture(GL_TEXTURE_2D, blurTextures[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SCREEN_WIDTH, SCREEN_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); } // set initial variables curBlurFrame = 0; blurTimer = 0; blurEnabled = true; moveBlur = false; cameraFrame.MoveForward(-10); return true; }
// This function does any needed initialization on the rendering // context. void SetupRC(void) { // Background glClearColor(0.2f, 0.2f, 0.3f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the torus gltMakeTorus(torusBatch, .70f, 0.10f, 11, 7); gltMakeCube(cubeBatch, 1.0f); toonShader = gltLoadShaderTripletWithAttributes("GSTessellate.vs", "GSTessellate.gs", "GSTessellate.fs", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locMVP = glGetUniformLocation(toonShader, "mvpMatrix"); locMV = glGetUniformLocation(toonShader, "mvMatrix"); locNM = glGetUniformLocation(toonShader, "normalMatrix"); static const GLfloat vertices[] = { -1.0f, -1.0f, -1.0f, // A -1.0f, -1.0f, 1.0f, // B -1.0f, 1.0f, -1.0f, // C -1.0f, 1.0f, 1.0f, // D 1.0f, -1.0f, -1.0f, // E 1.0f, -1.0f, 1.0f, // F 1.0f, 1.0f, -1.0f, // G 1.0f, 1.0f, 1.0f // H }; static const GLshort indices[] = { 0, 1, 2, 3, 2, 1, 1, 5, 3, 7, 3, 5, 5, 4, 7, 6, 7, 4, 4, 0, 6, 2, 6, 0, 4, 5, 0, 1, 0, 5, 3, 7, 2, 6, 2, 7 }; glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); glEnableVertexAttribArray(0); glGenBuffers(1, &element_buffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, element_buffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); GLenum e = glGetError(); }