Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to resize my texture. I am using cubemap to compute reflection. I want to use this cubemap to draw skybox. Skybox is drawn but I want to resize texture down, because it is dilated. As I wrote in my previous question (question), to draw skybox I use shaders:

//vertex shader        
uniform mat4 modelViewMatrix;
      uniform mat4 projectionMatrix;

        attribute vec4 position;
        varying mediump vec4 texCoord;
        void main() {
            texCoord = position;
            gl_Position = projectionMatrix * modelViewMatrix * position;


//fragment shader
uniform samplerCube Sampler;

    varying mediump vec4 texCoord;

     void main() {
         mediump vec3 cube = vec3(textureCube(Sampler,;
         gl_FragColor = vec4(cube, 1.0);

I send this data:

float vertices[24] = {  
    -1.0, -1.0,  1.0,
    1.0, -1.0,  1.0,
    -1.0,  1.0,  1.0,
    1.0,  1.0,  1.0,
    -1.0, -1.0, -1.0,
    1.0, -1.0, -1.0,
    -1.0,  1.0, -1.0,
    1.0,  1.0, -1.0,

In this order to draw cube:

GLubyte indices[14] = {0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1};

I think, that main problem is in the vertex shader, where I use vertex data as texture coord. But I have no idea how to map vertexes to cube map texture coordinates. Can you help me? Thanks

Edit: It is strange, but when I multiply modelviewMatrix with projectionMatrix it does not work. Now my code is:

    uniform mat4 modelViewMatrix;
  uniform mat4 projectionMatrix;
  uniform mat3 normalMatrix;

    attribute vec4 position;
    varying mediump vec3 texCoord;
    void main() {

        gl_Position = projectionMatrix * modelViewMatrix * position;
        texCoord = normalMatrix * (;

I have attached the screenshot, it looks quite good. Maybe it is distorted, because of the aspect ratio: screen

share|improve this question
Why don't you just resize the texture before loading (in e.g. Photoshop) or on loading? It will be much easier and faster. – Kromster Mar 31 '11 at 6:09
Can you give me a hint, how to resize it on loading? I am using PVR texture – martin pilch Mar 31 '11 at 7:53
I'm not familiar with iOS/PVR, maybe there are resizing functions in utils units. Just make another low-resolution version of your PVR texture in PVR-editing software and use it. – Kromster Mar 31 '11 at 9:18
Martin please, share screenshot so we can see the actual problem. – Notabene Mar 31 '11 at 10:04
I think i see the problem :). You have too big fov (field of view) in your perspective camera setup. This problem actualy really cannot be solved by resizing. And if you want to add something to you question, edit the question ;) – Notabene Mar 31 '11 at 18:26
up vote 2 down vote accepted

Texture cubes works differently than regular texturing. Texture cubes are indexed not by indicies on the polygon, but by a direction vector. Imagine that you are in the middle of the cube and texture coordinate are actualy 3D vector pointing to the texture cubes surface.

enter image description here

Resizing texture will not solve anything. You have to somehow change texture coordinates. But this problem doesn't seem to be caused by texture scale problem. It looks more like a too big field of view in perspective matrix, which can cause this problems.

//this should be OK.
gluPerspective(45.0f, width/height, zNear, zFar);

And the vertex shader should be like this:

void main() {
    gl_Position = modelViewMatrix * projectionMatrix * gl_Position;
    texCoord = gl_NormalMatrix *;

About gl_NormalMatrix

The matrix multiplication order should be really like this, if this (correct) order doesn't work, there is propably some error on other place...

(credits: That nice image was stolen from here)

share|improve this answer
@MartinPilch if this doesn't help, i would like to see whole code. You can share it via pastebin or something, if you want. – Notabene Mar 31 '11 at 18:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.