//procedura inicjuj¹ca ró¿ne sprawy zwi¹zane z rysowaniem w OpenGL void initOpenGL() { tex0 = readTexture("metal.tga"); tex1 = readTexture("stones2.tga"); tex2 = readTexture("latarka.tga"); setupShaders(); setupVBO(); setupVAO(); glEnable(GL_DEPTH_TEST); }
void MyD3DAssets::loadPSTexture(int textureIndex) { ID3D11ShaderResourceView *view = nullptr; context->base->PSGetShaderResources(textureIndex, 1, &view); if (view == nullptr) { PSTexture.free(); } else { ID3D11Resource *textureResource = nullptr; view->GetResource(&textureResource); ID3D11Texture2D* texture = nullptr; HRESULT hr = textureResource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&texture)); if (texture == nullptr || FAILED(hr)) { PSTexture.free(); g_logger->logErrorFile << "textureResource->QueryInterface failed" << endl; } else { readTexture(texture, PSTexture); texture->Release(); } textureResource->Release(); view->Release(); } }
int readTextureList() { printInt(14); printInt(2); printBytes("\xFF\xFF\xFF\xFF", 4); int beginningOffset = ftell(output); openBracket(); int numTextures = readInt("*TEXTURE_COUNT"); printInt(numTextures); int i; for (i = 0; i < numTextures; i++) { readTexture(); } closeBracket(); int endOffset = ftell(output); int size = endOffset - beginningOffset; fseek(output, beginningOffset - 4, 0); printInt(size); fseek(output, endOffset, 0); return numTextures; }
void addBackground(void) { if(first) { readTexture(); first=0; } glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // specify texture parameters - wrapping/filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Put the image in glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, DIM, DIM, 0, GL_RGB, GL_UNSIGNED_BYTE, texture); glBegin(GL_POLYGON); glTexCoord2f(0.0, 0.0); glVertex3f(-BG_SIZE, -BG_SIZE, 0.0); glTexCoord2f(1.0, 0.0); glVertex3f(BG_SIZE, -BG_SIZE, 0.0); glTexCoord2f(1.0, 1.0); glVertex3f(BG_SIZE, BG_SIZE, 0.0); glTexCoord2f(0.0, 1.0); glVertex3f(-BG_SIZE, BG_SIZE, 0.0); glEnd(); glDisable(GL_TEXTURE_2D); }
std::shared_ptr<gameplay::Material> OBJWriter::readMaterial(const boost::filesystem::path& path, const std::shared_ptr<gameplay::ShaderProgram>& shaderProgram) const { auto texture = readTexture(path); auto sampler = std::make_shared<gameplay::Texture::Sampler>(texture); sampler->setWrapMode(gameplay::Texture::CLAMP, gameplay::Texture::CLAMP); auto material = std::make_shared<gameplay::Material>(shaderProgram); material->getParameter("u_diffuseTexture")->set(sampler); material->getParameter("u_worldViewProjectionMatrix")->bindWorldViewProjectionMatrix(); material->initStateBlockDefaults(); return material; }
static void init() { fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); menuInit(); readTexture(textureLocation); createProgram("convolution.vert", "convolution.frag"); glEnable(GL_TEXTURE_2D); glClearColor(1.0, 1.0, 1.0, 1.0); /*glShadeModel(GL_SMOOTH);*/ glShadeModel(GL_FLAT); }
void myD3D11DeviceContext::readSwapChain(Bitmap &result) { ID3D11Texture2D* swapChainTexture; HRESULT hr = assets->swapChain->base->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast< void** >(&swapChainTexture)); if (FAILED(hr)) { g_logger->logErrorFile << "assets.swapChain->base->GetBuffer failed" << endl; } else { readTexture(swapChainTexture, result); } swapChainTexture->Release(); }
void LoaderDFF::readMaterial(GeometryPtr &geom, const RWBStream &stream) { auto materialStream = stream.getInnerStream(); auto matStructID = materialStream.getNextChunk(); if (matStructID != CHUNK_STRUCT) { throw DFFLoaderException("Material missing struct chunk"); } char *matData = materialStream.getCursor(); Geometry::Material material; // Unkown matData += sizeof(std::uint32_t); material.colour = *(glm::u8vec4 *)matData; matData += sizeof(std::uint32_t); // Unkown matData += sizeof(std::uint32_t); /*bool usesTexture = *(std::uint32_t*)matData;*/ matData += sizeof(std::uint32_t); material.ambientIntensity = *(float *)matData; matData += sizeof(float); /*float specular = *(float*)matData;*/ matData += sizeof(float); material.diffuseIntensity = *(float *)matData; matData += sizeof(float); material.flags = 0; RWBStream::ChunkID chunkID; while ((chunkID = materialStream.getNextChunk())) { switch (chunkID) { case CHUNK_TEXTURE: readTexture(material, materialStream); break; default: break; } } geom->materials.push_back(material); }
int Model::readObj(string filename) { ifstream stream(filename); if (stream.is_open()) { string line, chunk; while (stream >> chunk) { getline(stream, line); if (chunk == "v") readVertex(line); else if (chunk == "vn") readNormal(line); else if (chunk == "vt") readTexture(line); else if (chunk == "f") readFace(line); } // If we have normals or texture coordinates, we need to rearrange everything to avoid multiple indices. // TODO: Do this without blowing up the size of the v/n/t buffers. if (nBuffer.size() > 0 || tBuffer.size() > 0) { vector<glm::vec4> vBuffer2; vector<glm::vec3> nBuffer2; vector<glm::vec2> tBuffer2; for (unsigned int i = 0; i < viBuffer.size(); i++) { vBuffer2.push_back(vBuffer[viBuffer[i]]); if (niBuffer.size() > 0) nBuffer2.push_back(nBuffer[niBuffer[i]]); if (tiBuffer.size() > 0) tBuffer2.push_back(tBuffer[tiBuffer[i]]); } vBuffer = vBuffer2; nBuffer = nBuffer2; tBuffer = tBuffer2; } stream.close(); return 0; }
/** * Ray-trace function that returns what texel you hit in the * cube map, since any ray will hit some point in the cube map */ glm::vec3 rayTrace(Ray &ray, const float& t, RayTracerState& state) { glm::vec3 out_color(0.0f); glm::vec3 dir = ray.getDirection(); glm::vec2 coords; float s1, t1; float largest = glm::max(glm::max(abs(dir.x),abs(dir.y)), abs(dir.z)); if (abs(dir.x) == largest) { if (dir.x > 0.0f){ //POS X side s1 = 0.5f - (0.5f * dir.z / dir.x ); t1 = 0.5f - (0.5f * dir.y / dir.x ); out_color = readTexture(posx, s1, t1); } else{ //NEG X s1 = 0.5f - (0.5f * dir.z / dir.x); t1 = (dir.y/ dir.x + 1.0f) * 0.5f; out_color = readTexture(negx, s1, t1); } } else if(abs(dir.y) == largest){ if (dir.y > 0.0f){ // POS Y s1 = (dir.x / dir.y + 1.0f) * 0.5f; t1 = (dir.z / dir.y + 1.0f) * 0.5f; out_color = readTexture(posy, s1, t1); } else{ // NEG Y s1 = 0.5f - (0.5f * dir.x / dir.y); t1 = (dir.z/ dir.y + 1.0f) * 0.5f; out_color = readTexture(negy, s1, t1); } } else if(abs(dir.z) == largest){ if (dir.z > 0.0f){ // POS Z s1 = (dir.x / dir.z + 1.0f) * 0.5f; t1 = 0.5f - (0.5f * dir.y / dir.z ); out_color = readTexture(posz, s1, t1); } else{ // NEG Z s1 = (dir.x / dir.z + 1.0f) * 0.5f; t1 = (dir.y / dir.z + 1.0f) * 0.5f; out_color = readTexture(negz, s1, t1); } } ray.invalidate(); return out_color; }
void myD3D11DeviceContext::readRenderTarget(Bitmap &result) { ID3D11RenderTargetView *view; assets->context->base->OMGetRenderTargets(1, &view, nullptr); ID3D11Resource *resource; view->GetResource(&resource); ID3D11Texture2D *inputTexture; HRESULT hr = resource->QueryInterface(__uuidof(ID3D11Texture2D), (void **)&inputTexture); if (FAILED(hr)) { g_logger->logErrorFile << "QueryInterface failed to cast to a texture" << endl; } else { readTexture(inputTexture, result); } view->Release(); }