diff options
author | Michael Rodin <mrodin@de.adit-jv.com> | 2018-11-15 12:45:18 +0100 |
---|---|---|
committer | Michael Rodin <mrodin@de.adit-jv.com> | 2018-11-27 16:51:39 +0100 |
commit | 329ebb83432854737cec5d7c91fa11a5a1411ec8 (patch) | |
tree | a663c96cbb2d5c8b1f7b50e7e33cf5d51307c667 | |
parent | 17ceb14ba5ed50f5f6d9507679f4a089c64644e0 (diff) | |
download | wayland-ivi-extension-329ebb83432854737cec5d7c91fa11a5a1411ec8.tar.gz |
EGLWLMockNavigation: use textures for streets
Add a new constructor to the class Street and modify
the rendering function so textures can be used
for rendering streets. Modify MockNavi::generateCity(),
so textures are loaded and used if available
Signed-off-by: Michael Rodin <mrodin@de.adit-jv.com>
3 files changed, 62 insertions, 6 deletions
diff --git a/ivi-layermanagement-examples/EGLWLMockNavigation/include/Street.h b/ivi-layermanagement-examples/EGLWLMockNavigation/include/Street.h index 5193715..a597b19 100644 --- a/ivi-layermanagement-examples/EGLWLMockNavigation/include/Street.h +++ b/ivi-layermanagement-examples/EGLWLMockNavigation/include/Street.h @@ -1,6 +1,7 @@ /*************************************************************************** * * Copyright 2010,2011 BMW Car IT GmbH + * Copyright (C) 2018 Advanced Driver Information Technology Joint Venture GmbH * * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,6 +23,8 @@ #include "IRenderable.h" #include "IUpdateable.h" #include "vec.h" +#include "TextureLoader.h" +#include "ShaderTexture.h" class ShaderBase; @@ -29,6 +32,7 @@ class Street : public IRenderable, public IUpdateable { public: Street(vec3f position, vec3f size, vec4f color, ShaderBase* shader); + Street(vec3f position, vec3f size, vec4f color, ShaderTexture* shader, TextureLoader* texture, float numRepeats = 2.0); virtual ~Street() {} virtual void render(); @@ -41,6 +45,9 @@ private: vec3u m_index[2]; vec3f m_vertex[4]; + vec2f m_texCoords[4]; + bool withTexture = false; + TextureLoader* texture = nullptr; ShaderBase* m_shader; }; diff --git a/ivi-layermanagement-examples/EGLWLMockNavigation/src/MockNavi.cpp b/ivi-layermanagement-examples/EGLWLMockNavigation/src/MockNavi.cpp index e73481c..18eb2f2 100644 --- a/ivi-layermanagement-examples/EGLWLMockNavigation/src/MockNavi.cpp +++ b/ivi-layermanagement-examples/EGLWLMockNavigation/src/MockNavi.cpp @@ -73,6 +73,8 @@ void MockNavi::generateCity() ShaderTexture* pShaderTexture = new ShaderTexture(projection); TextureLoader* carTexture = new TextureLoader; bool carTextureLoaded = carTexture->loadBMP("/usr/share/wayland-ivi-extension/textures/car.bmp"); + TextureLoader* streetTexture = new TextureLoader; + bool streetTextureLoaded = streetTexture->loadBMP("/usr/share/wayland-ivi-extension/textures/street.bmp"); // generate base plate vec4f groundColor(0.8, 0.8, 0.6, 1.0); @@ -83,9 +85,14 @@ void MockNavi::generateCity() // generate street z direction vec4f streetColor(0.0, 0.0, 0.0, 1.0); - vec3f streetPosition = vec3f(0.6 * CITY_GRID_SIZE, 0.0, 0.0); - vec3f streetSize = vec3f(CITY_GRID_SIZE * 0.6, 0.0, -CITY_GRID_SIZE * 2.0 * m_houseCount); - Street* obj = new Street(streetPosition, streetSize, streetColor, pShader); + vec3f streetPosition = vec3f(0.6 * CITY_GRID_SIZE, 0.001, 0.0); + vec3f streetSize = vec3f(CITY_GRID_SIZE * 0.6, 0.0, -CITY_GRID_SIZE * 2.0 * m_houseCount * 200.0); + Street* obj = nullptr; + if(streetTextureLoaded){ + obj = new Street(streetPosition, streetSize, streetColor, pShaderTexture, streetTexture); + }else{ + obj = new Street(streetPosition, streetSize, streetColor, pShader); + } m_renderList.push_back(obj); // generate streets x direction @@ -94,7 +101,12 @@ void MockNavi::generateCity() vec4f streetColor(0.0, 0.0, 0.0, 1.0); vec3f streetPosition = vec3f(0.0, 0.0, 0.6 - z * CITY_GRID_SIZE); vec3f streetSize = vec3f(CITY_GRID_SIZE * 3, 0.0, CITY_GRID_SIZE * 0.6); - Street* obj = new Street(streetPosition, streetSize, streetColor, pShader); + Street* obj = nullptr; + if(streetTextureLoaded){ + obj = new Street(streetPosition, streetSize, streetColor, pShaderTexture, streetTexture); + }else{ + obj = new Street(streetPosition, streetSize, streetColor, pShader); + } m_renderList.push_back(obj); m_updateList.push_back(obj); } diff --git a/ivi-layermanagement-examples/EGLWLMockNavigation/src/Street.cpp b/ivi-layermanagement-examples/EGLWLMockNavigation/src/Street.cpp index 6ee6e1d..46e5230 100644 --- a/ivi-layermanagement-examples/EGLWLMockNavigation/src/Street.cpp +++ b/ivi-layermanagement-examples/EGLWLMockNavigation/src/Street.cpp @@ -2,6 +2,7 @@ * * Copyright 2010,2011 BMW Car IT GmbH * Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh + * Copyright (C) 2018 Advanced Driver Information Technology Joint Venture GmbH * * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -61,9 +62,45 @@ Street::Street(vec3f position, vec3f size, vec4f color, ShaderBase* shader) m_vertex[3].z = m_position.z + m_size.z; } +Street::Street(vec3f position, vec3f size, vec4f color, ShaderTexture* shader, TextureLoader* streetTexture, float numRepeats) +: Street(position, size, color, shader) +{ + withTexture = true; + texture = streetTexture; + float xCoords, yCoords; + + float z_to_x = m_size.z / m_size.x; + float x_to_z = m_size.x / m_size.z; + if(z_to_x > x_to_z){ + yCoords = numRepeats; + xCoords = numRepeats * z_to_x; + } else { + yCoords = numRepeats * z_to_x; + xCoords = numRepeats; + } + + m_texCoords[0].x = 0.0; + m_texCoords[0].y = 0.0; + + m_texCoords[1].x = xCoords; + m_texCoords[1].y = 0.0; + + m_texCoords[2].x = xCoords; + m_texCoords[2].y = yCoords; + + m_texCoords[3].x = 0.0; + m_texCoords[3].y = yCoords; +} + void Street::render() { - m_shader->use(&m_position, &m_color); + if(withTexture) { + GLuint textureID = texture->getId(); + ((ShaderTexture *)m_shader)->use(&m_position, textureID); + ((ShaderTexture *)m_shader)->setTexCoords(m_texCoords); + }else{ + m_shader->use(&m_position, &m_color); + } // draw glEnableVertexAttribArray(0); @@ -78,6 +115,6 @@ void Street::update(int currentTimeInMs, int lastFrameTime) if (m_position.z > 3.0) { - m_position.z -= 2 * 2.0; + m_position.z -= 2.0; } } |