void Scene::render() { //Keep the cubes rotating mCubeRotation += .05f; if(mCubeRotation > 1.0f) mCubeRotation = 0.0f; ////Reset cube1World //mCube1World = glm::mat4(); ////Define cube1's world space matrix //mRotation = glm::cross(mRotation, glm::angleAxis(mCubeRotation * 180.f / 3.14f, glm::vec3(0,1,0))); //glm::mat4 translation = glm::translate( 0.0f, 0.0f, 4.0f ); ////Set cube1's world space using the transformations //mCube1World = translation * glm::toMat4(mRotation); ////Reset cube2World //mCube1World = glm::mat4(); ////Define cube2's world space matrix //mRotation = glm::cross(-mRotation, glm::angleAxis(mCubeRotation * 180.f / 3.14f, glm::vec3(0,1,0))); //glm::mat4 scale = glm::scale( 1.3f, 1.3f, 1.3f ); ////Set cube2's world space matrix //mCube2World = glm::toMat4(mRotation) * scale; //glm::vec4 camPos = glm::vec4( 0.0f, 3.0f, -8.0f, 0.0f ); //glm::mat4 camProjection = glm::perspective(70.f, mWidth / (float)mHeight, 0.1f, 1000.0f); //glm::mat4 camView = glm::translate(glm::vec3(0,0,-3.5)); //glm::mat4 WVP = camProjection * camView * mCube1World; // //CGparameter location = cgGetNamedParameter(mVertexShaderId, "matrices.WVP"); //cgSetMatrixParameterfc(location, glm::value_ptr(WVP)); // do 3D rendering on the back buffer here //UINT stride = sizeof(VERTEX); //UINT offset = 0; //mDeviceContext->Draw(4, 0); unsigned int strides[2] = { sizeof(glm::vec3), sizeof(glm::vec4) }; unsigned int offsets[2] = { 0, 0 }; //dev->IASetVertexBuffers(0, 2, &pVBuffer, strides, offsets ); //mDeviceContext->IASetInputLayout(mVboLayout); // this needs to be done to really set it //mDeviceContext->IASetVertexBuffers(0, 2, mVbo, strides, offsets); //mDeviceContext->IASetIndexBuffer( mIbo, DXGI_FORMAT_R16_UINT, 0 ); //mDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //mDeviceContext->DrawIndexed(36, 0, 0); // GETTING A LOCATION CAN BE DONE WHEN A SHADER IS BOUND CGparameter location2 = cgGetNamedParameter(mVertexShaderId, "ambient"); cgD3D11UnbindProgram(mVertexShaderId); cgD3D11UnbindProgram(mFragmentShaderId); // We can only set the uniform if the shader is NOT BOUND! // In OpenGL we have to check that! // FOUND OUT: a location can be retrieved and set to a value when a shader is not bound! // BUT SETTING IT's VALUE CAN ONLY BE DONE WHEN IT's UNBOUND! cgSetParameter4fv(location2, glm::value_ptr(glm::vec4(0.5,mCubeRotation,1.0,1.0))); checkForCgError("could not set uniform color", mCgContext, false); bindShader(mVertexShaderId, mFragmentShaderId); mDeviceContext->IASetInputLayout(mVboLayout); // this needs to be done to really set it mDeviceContext->IASetVertexBuffers(0, 2, mPlaneVbo, strides, offsets); mDeviceContext->IASetIndexBuffer( mPlaneIbo, DXGI_FORMAT_R32_UINT, 0 ); mDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); mDeviceContext->DrawIndexed(6, 0, 0); }
void CgShaderProgramD3D11::unbind() { cgD3D11UnbindProgram(cgProgram_); }
void CgDxShader::unbind() { if(mProgram) cgD3D11UnbindProgram(mProgram); }