Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: Cubemap skybox

  1. #1
    Newbie Newbie
    Join Date
    Feb 2014
    Posts
    1

    Cubemap skybox

    I have been following the OpenGL Superbible 6th Edition and I've come across a wall. I'm using almost identical code to what's supplied in the samples, except where necessary I have rolled my own.
    I am getting desperate, I can't seem to get this to work AT ALL, all I see on the screen is black. My custom functions do work, and have worked for other applications so they can't be the problem.
    If any more information is required please let me know.

    Here is my code:
    Code :
    glGenTextures(1, &m_TextureID);
        glActiveTexture(GL_TEXTURE0);
    	glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
     
     
    	glBindTexture(GL_TEXTURE_CUBE_MAP, m_TextureID);
     
    	unsigned char* pixelData1[6];
    	int width = 0; int height = 0; int channels = 0;
    	pixelData1[0] = SOIL_load_image(m_TextureFiles[0], &width, &height, &channels, SOIL_LOAD_AUTO);
        glTexStorage2D(GL_TEXTURE_CUBE_MAP, 0, GL_RGB, width, height);
     
     
    	for ( int i = 0; i < 6; ++i)
    	{
    		printf("Width: %i Height: %i Channels: %i\n", width, height, channels);					// data + face * face_size_in_bytes
            glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i,0,0,0,2048,1536,GL_RGB,GL_UNSIGNED_BYTE, pixelData1[0] + ((3*width)*height) * i );
     
    	}
     
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     
     
        //object.load("media/objects/dragon.sbm");
     
        //// load shaders and link shader program
    	m_vertShader = Utility::loadShader("../../Build/Shaders/skybox.vert", GL_VERTEX_SHADER);
    	m_fragShader = Utility::loadShader("../../Build/Shaders/skybox.frag", GL_FRAGMENT_SHADER);
     
    	// our vertex buffer has 3 properties per-vertex
    	const char* inputs[] = { "view_matrix" };
    	m_skyboxShader = Utility::createProgram(m_vertShader,0,0,0,m_fragShader, 0, 0);
     
    	m_vertShader = Utility::loadShader("../../Build/Shaders/render.vert", GL_VERTEX_SHADER);
    	m_fragShader = Utility::loadShader("../../Build/Shaders/render.frag", GL_FRAGMENT_SHADER);
     
    	// our vertex buffer has 3 properties per-vertex
    	const char* inputs1[] = { "position", "normal" };
    	m_renderShader = Utility::createProgram(m_vertShader,0,0,0,m_fragShader, 2, inputs1);
     
        glGenVertexArrays(1, &m_vao);
        //glBindVertexArray(m_vao);
     
        glDepthFunc(GL_LEQUAL);

    And my draw call:

    Code :
    	glDisable( GL_CULL_FACE );
     
        glBindTexture(GL_TEXTURE_CUBE_MAP, m_TextureID);
     
     
    	glUseProgram(m_skyboxShader);
        glBindVertexArray(m_vao);
     
    	GLint uView = glGetUniformLocation(m_skyboxShader, "view_matrix");
        glUniformMatrix4fv(uView, 1, GL_FALSE, glm::value_ptr(view));
     
     
        glDisable(GL_DEPTH_TEST);
     
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
     
    	glBindVertexArray(0);
    	glUseProgram(0);
     
     
        glEnable(GL_DEPTH_TEST);

    Shaders:

    Code :
    // Vert...
     
    #version 410 core
     
    uniform mat4 mv_matrix;
    uniform mat4 proj_matrix;
     
    layout (location = 0) in vec4 position;
    layout (location = 1) in vec3 normal;
     
    out VS_OUT
    {
        vec3 normal;
        vec3 view;
    } vs_out;
     
    void main(void)
    {
        vec4 pos_vs = mv_matrix * position;
     
        vs_out.normal = mat3(mv_matrix) * normal;
        vs_out.view = pos_vs.xyz;
     
        gl_Position = proj_matrix * pos_vs;
    }
     
    // Fragment....
     
    #version 410 core
     
    uniform samplerCube tex_cubemap;
     
    in VS_OUT
    {
        vec3    tc;
    } fs_in;
     
    layout (location = 0) out vec4 color;
     
    void main(void)
    {
        color = texture(tex_cubemap, fs_in.tc);
    }
    Last edited by Rifiul; 02-13-2014 at 02:12 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •