Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Sky box issue

  1. #11
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    12
    Quote Originally Posted by tksuoran View Post
    I am just guessing here, but I would suspect the transformation that you use for the sky object is not quite right.

    Try rendering the sky with some simple transformations. First try with identity transform. This should give a "working" but fixed, non-rotating sky. The next step would be to try some rotation only transform.
    Transformation? this is the code that starts the draw method
    Code :
    glPushMatrix();               
                    glPushAttrib(GL_ENABLE_BIT);
     
                    glLoadIdentity();   
                    GL13.glActiveTexture(GL13.GL_TEXTURE0);
                    glEnable(GL_TEXTURE_2D);
    //                glDepthRange(0, 1);
     
                  //load textures
                    textures = new Vector<Texture>();
                    try 
                    {                   	
                        textures.add(ImageLoader.loadTexture("Sky/front", "PNG"));
                        textures.add(ImageLoader.loadTexture("Sky/left", "PNG"));
                        textures.add(ImageLoader.loadTexture("Sky/back", "PNG"));
                        textures.add(ImageLoader.loadTexture("Sky/right", "PNG"));
                        textures.add(ImageLoader.loadTexture("Sky/top", "PNG"));
                        textures.add(ImageLoader.loadTexture("Sky/bottom", "PNG"));
                    }
                    catch (Exception e)
                    {
                    	System.out.println(e.getStackTrace().toString());
                    	System.out.println(e.getMessage());
                    	System.out.println(e.getCause());
                    	System.out.println(e.getLocalizedMessage());
                    }                
     
                    glRotatef(-cam.roll() + 180,  0, 0, -1);
                    glRotatef(-cam.pitch(), 1, 0, 0);
                    glRotatef(-cam.yaw(),   0, 1, 0);
    //                glScalef(15,15, 15);
     
                    // Just in case set all vertices to white.
                glColor4f(1,1,1,1);

    then farther down it has 6 glbegin(GL_QUADS) and such. Also Identity Transform? how do I do that? I'm using LWJGL (which is openGL) for Java. (Also have Slick and Slick utils too)

  2. #12
    Junior Member Regular Contributor tksuoran's Avatar
    Join Date
    Mar 2008
    Location
    Cambridge, UK
    Posts
    224
    Your transformation looks plausible for a sky object: There is LoadIndentity, followed by some rotations (and commented out scale). What I don't see is a call to MatrixMode, so it would be possible that your matrix mode is something wrong (not modelview).

    You should not be loading textures in the drawing code. Textures should be loaded before any drawing takes place.

    There is not much texture setup code visible. You need to bind the texture and setup texture environment.

    You should learn modern way to program OpenGL (shaders etc.) instead of the old fixed function way.

  3. #13
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    12
    Quote Originally Posted by tksuoran View Post
    Your transformation looks plausible for a sky object: There is LoadIndentity, followed by some rotations (and commented out scale). What I don't see is a call to MatrixMode, so it would be possible that your matrix mode is something wrong (not modelview).

    You should not be loading textures in the drawing code. Textures should be loaded before any drawing takes place.

    There is not much texture setup code visible. You need to bind the texture and setup texture environment.

    You should learn modern way to program OpenGL (shaders etc.) instead of the old fixed function way.
    Code :
    private static void render() 
        {
                //glPolygonMode(GL_FRONT, GL_POINT);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
            glLoadIdentity();
     
            cam.applyTranslations();
            bound.setX((int)cam.x()-CHUNK_SIZE/2);
            bound.setY((int)cam.z()-CHUNK_SIZE/2);
            glLight(GL_LIGHT0, GL_POSITION, BufferTools.asFlippedFloatBuffer(cam.x(), cam.y(), cam.z(), 1));
            glUseProgram(terrainShader);
            sky.draw();
            terrain.draw(bound);
            glUseProgram(0);
            glMatrixMode(GL_PROJECTION);
            glLoadMatrix(orthographicProjectionMatrix);
            glMatrixMode(GL_MODELVIEW);
            glPushMatrix();
            glLoadIdentity();
            glDisable(GL_LIGHTING);
            glClear(GL_DEPTH_BUFFER_BIT);
            if(showDevInfo)
            {
                    font.drawString(10, 10, "Position:\nX: " + 
                    		formatter.format(cam.x()) +
                            "\nY: " + 
                    		formatter.format(cam.y()) +
                            "\nZ: " + 
                    		formatter.format(cam.z()) +
                    		"\nPitch" +
                    		formatter.format(cam.pitch()) +
                            "\nYaw: " + 
                    		formatter.format(cam.yaw()) +
                            "\nRoll: " + 
                    		formatter.format(cam.roll()));
            }
     
            hud.draw();
            glEnable(GL_LIGHTING);
            glPopMatrix();
            glMatrixMode(GL_PROJECTION);
            glLoadMatrix(perspectiveProjectionMatrix);
            glMatrixMode(GL_MODELVIEW);            
        }

    I do have shaders setup and run, as I was trying to get multitexturing to work for the terrain, saddly it either just merged my two textures then painted them, instead of what I wanted it to do (slopes are rock, flatter areas are grass)

    I'm still very new to OpenGL and there are no good JAVA tutorials out there (lots of C++) But I moved the texture loading into the constructor, instead of loading the textures to infinity through the draw method.

    And setup the texture enviroment? like
    Code :
     private void clampToEdge() {
                    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
                    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
                    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
                    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            }
    the clampToEdge method?

    I've been a programmer for a few years now, and a 3d Modeler/animator. But I've never actually worked with graphical/3d rendering (other then really simple 2d Sprites)
    Watched some tutorials on rendering modes and that VBOs is by far the closest to the best one you can use (display list are fast, but outdated, and cannot be altered during use)

    Click image for larger version. 

Name:	Screen2.jpg 
Views:	38 
Size:	95.7 KB 
ID:	1105

    this is the current screen shot. Have an issue with the HUD since it doesn't respect drawing two images on each other even if they have Alpha (but that's another issue)

Posting Permissions

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