Directly drawn open Gl doesn't scale with layer..

I’m using Cocos2d0-x 3.0 Beta 2

In my world Layer I have a method that draws directly using openGl

	// Tell OpenGL this is the texture we're using
		GL::bindTexture2D(_subterraneanTexture->getName());

		// wrap in both the S and T directions (that's X and Y for the rest of us!)
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

		// Enable the arrays
		GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORDS);

		_glProgram->use();

		_glProgram->setUniformsForBuiltins();

		// Give OpenGl our array of points that we want to fill
		glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(cocos2d::Point), _subterraneanFloorTextureTrianglePoints);
		// Give OpenGl the array of points in the texture we want to use to fill the above array of points
		glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, sizeof(cocos2d::Point), _subterraneanFloorTexturePoints);

		// Tell OpenGl to draw the arrays we gave it
		glDrawArrays(GL_TRIANGLE_STRIP, 0, _numberOfFloorSubterraneanTextureTrianglePoints);

This is in a method that is called via

	_customCommand.init(_globalZOrder);
	_customCommand.func = CC_CALLBACK_0(WorldLayer::drawSubterrains, this);
	Director::getInstance()->getRenderer()->addCommand(&_customCommand);

which is in the layer’s overridden draw() method.

This layer is added as a child to a layer (zoomlayer) as are most other sprites etc.

When I change the scale of the zoom layer, all of my assets scale appropriately, but the directly drawn stuff doesn’t.

Does anyone have a suggestion as to how I may be able to fix this?

Thanks

@Maxxx

I think your problems is due to the transform not be updated properly when you scale your zoomlayer.

You should transform your quards with modelViewTransform before the custom commands be executed by the render.

Here is the code piece I grab it from the LayerColor:

void LayerColor::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
{
    _customCommand.init(_globalZOrder);
    _customCommand.func = CC_CALLBACK_0(LayerColor::onDraw, this, transform, transformUpdated);
    renderer->addCommand(&_customCommand);
    //I think you forget to add the following transforms code
    for(int i = 0; i < 4; ++i)
    {
        kmVec3 pos;
        pos.x = _squareVertices[i].x; pos.y = _squareVertices[i].y; pos.z = _positionZ;
        kmVec3TransformCoord(&pos, &pos, &_modelViewTransform);
        _noMVPVertices[i] = Vertex3F(pos.x,pos.y,pos.z);
    }
}

@0owen
Thanks.
i tried adding that code (which, I confess, I don’t understand at all!) to my draw() method - but it made no difference :frowning: :frowning: :frowning:

in order to do so I had to chnage my layer to inherit from LayerColor rather than Layer

But I still saw no difference

@Maxxx

I think I have made some mistake.

Try to add

_modelViewTransform = this->transform(parentTransform);

before calling

  //I think you forget to add the following transforms code
    for(int i = 0; i < 4; ++i)
    {
        kmVec3 pos;
        pos.x = _squareVertices[i].x; pos.y = _squareVertices[i].y; pos.z = _positionZ;
        kmVec3TransformCoord(&pos, &pos, &_modelViewTransform);
        _noMVPVertices[i] = Vertex3F(pos.x,pos.y,pos.z);
    }

@Maxxx

If you can make a sample project to me, I will be glad to help.

Here is my email: guanghui.qu@cocos2d-x.org

@Maxxx
I guess it could be caused by sending a wrong transform to shader
could you please try this code instead of your code:

    GL::bindTexture2D(_subterraneanTexture->getName());

    // wrap in both the S and T directions (that's X and Y for the rest of us!)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    // Enable the arrays
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORDS);

    _glProgram->use();

    //_glProgram->setUniformsForBuiltins();
    //change to this
    _glProgram->setUniformsForBuiltins(_modelViewTransform);

@dabingnn You, sir, are a genius!

Thank you so much. That is something I would never have found, I think.

Thanks also to @0owen for your help

It’s scaling perfectly now!

Aha, It is our pleasure to serve you.