Basic rendering

i got the basic window set up properly but now i am having a hard time trying to figure out how to draw to my new screen…



   protected void render(float arg0)
   {
      display.getRenderer().clearBuffers();
      
      Vector3f vertex[]=new Vector3f[3];
         vertex[0]=new Vector3f(1,1,0);
         vertex[1]=new Vector3f(0,0,0);
         vertex[2]=new Vector3f(1,0,0);
      
      ColorRGBA color[]=new ColorRGBA[3];
         color[0]=new ColorRGBA(1,1,0,1);
         color[1]=new ColorRGBA(0,0,0,1);
         color[2]=new ColorRGBA(1,0,0,1);
      
      Geometry square=new Geometry("Box",vertex,null,color,null);
      
      square.draw(display.getRenderer());
      display.getRenderer().displayBackBuffer();
   }



this is what i put in my render method. i know this is not where you want to be setting things up. but for now thats where i have it. i have the camera set to the basic setting that is listed in tutorials for the jme. do i just have it pointed in the wrong direction? any help would be greatly appreciated.

thanks

Most of the calls you have there aren’t necessary. Normally you’d set up your geometry in initGame(), rather than in render(), and you’d attach it to a Node (or a hierarchy of Nodes, if you like).



The best thing to do would be to download the source code, and adapt one of the tutorials, such as TestBezierCurve or something. That will give you an idea of what you need to do in each method.

First, I’d like to reiterate what Fuseboy said.



But, since I know you are just playing around, let’s go ahead and try to figure out why you can’t see your triangle. Firstly, how is your camera set? Are you using a camera? What’s your camera’s location if you are? Since you are drawing your triangle at z location (0), you need to make sure that camera is far enough away. I’d try making z (-10) that will move the triangle 10 units into the screen.

"mojomonk" wrote:
I'd try making z (-10) that will move the triangle 10 units into the screen.

Or try z as positive 10, depending on the direction your camera is facing.

i’ve been trying to find the source code to some demo’s but i can’t find any.



i’ll try looking at the camera location and direction and see what i can find out.

here is what i got in my initSystem() method…



protected void initSystem()
   {
      try
      {
         display=new LWJGLDisplaySystem();
         display.createWindow(properties.getWidth(),properties.getHeight(),properties.getDepth(),properties.getFreq(),properties.getFullscreen());
         display.setTitle("Window");
         display.setVSyncEnabled(true);
         
         ColorRGBA bgColor = new ColorRGBA(0f, 0f, 0f, 1f);
         display.getRenderer().setBackgroundColor(bgColor);
         
         cam=new LWJGLCamera(properties.getWidth(), properties.getHeight());
      }
      catch(JmeException e)
      {
         e.printStackTrace();
         System.exit(1);
      }
      
      cam.setFrustum(1f, 1000f, -0.55f, 0.55f, 0.4125f, -0.4125f);
      Vector3f loc = new Vector3f(0, 0, -10);
      Vector3f left = new Vector3f(0, -1, 0);
      Vector3f up = new Vector3f(0, 1, 0);
      Vector3f dir = new Vector3f(1, 0, 0);
      cam.setFrame(loc, left, up, dir);

      display.getRenderer().setCamera(cam);
      
      this.setLogicTicksPerSecond(1);
      
      System.out.println("System Initiated.");
   }



i played with the cam loc a bit. hence the radom values. i assume i am missing the needed calls here.

Ok, let’s play with a basic camera:



set it to:



left (-1, 0, 0);

up (0,1,0);

dir(0,0,-1);



set the location to (0,0,20);



you’re camera will now be looking down the negative z (towards (0,0,0)).



now try rendering.

but render not with square.draw(display.getRenderer());

but display.getRenderer().draw(square);

i am missing something somewhere. i dunno what it is. i set up the camera like you said but i am still getting nothing… :frowning:



is there some source code i can look at for the demos you have or something?

In cvs is jme and jmetest source. The tests now use simple game which sets up the camera and everything for you. So it might not help to explain your problem. I’ll post an old test here that builds a simple triangle and renders it:


/*
 * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
 * names of its contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * 
 */
package jmetest.renderer;

import com.jme.app.BaseGame;
import com.jme.bounding.BoundingSphere;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Camera;
import com.jme.scene.Node;
import com.jme.scene.TriMesh;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;

/**
 * Test for trimesh part of the renderer.
 *
 * @author Mark Powell
 */
public class TestLWJGLRendererTriMesh extends BaseGame {

    private TriMesh t;

    private Camera cam;

    private Node scene;

    /**
     * Entry point for the test,
     *
     * @param args
     */
    public static void main(String[] args) {
        TestLWJGLRendererTriMesh app = new TestLWJGLRendererTriMesh();
        app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
    }

    /**
     * Not used in this test.
     *
     * @see com.jme.app.SimpleGame#update()
     */
    protected void update(float interpolation) {

    }

    /**
     * clears the buffers and then draws the TriMesh.
     *
     * @see com.jme.app.SimpleGame#render()
     */
    protected void render(float interpolation) {
        display.getRenderer().clearBuffers();

        display.getRenderer().draw(scene);

    }

    /**
     * creates the displays and sets up the viewport.
     *
     * @see com.jme.app.SimpleGame#initSystem()
     */
    protected void initSystem() {
        try {
               display = DisplaySystem.getDisplaySystem(properties.getRenderer());
                display.createWindow(properties.getWidth(), properties
                        .getHeight(), properties.getDepth(), properties
                        .getFreq(), properties.getFullscreen());
                cam = display.getRenderer().getCamera(properties.getWidth(),
                        properties.getHeight());
           
        } catch (JmeException e) {
            e.printStackTrace();
            System.exit(1);
        }
        ColorRGBA blueColor = new ColorRGBA();
        blueColor.r = 0;
        blueColor.g = 0;
        display.getRenderer().setBackgroundColor(blueColor);
        cam.setFrustum(1.0f, 1000.0f, -0.55f, 0.55f, 0.4125f, -0.4125f);
        Vector3f loc = new Vector3f(4.0f, 0.0f, 0.0f);
        Vector3f left = new Vector3f(0.0f, -1.0f, 0.0f);
        Vector3f up = new Vector3f(0.0f, 0.0f, 1.0f);
        Vector3f dir = new Vector3f(-1.0f, 0f, 0.0f);
        cam.setFrame(loc, left, up, dir);
        display.getRenderer().setCamera(cam);

    }

    /**
     * builds the trimesh.
     *
     * @see com.jme.app.SimpleGame#initGame()
     */
    protected void initGame() {
        Vector3f[] verts = new Vector3f[3];
        ColorRGBA[] color = new ColorRGBA[3];

        verts[0] = new Vector3f();
        verts[0].x = -50;
        verts[0].y = 0;
        verts[0].z = 0;
        verts[1] = new Vector3f();
        verts[1].x = -50;
        verts[1].y = 25;
        verts[1].z = 25;
        verts[2] = new Vector3f();
        verts[2].x = -50;
        verts[2].y = 25;
        verts[2].z = 0;

        color[0] = new ColorRGBA();
        color[0].r = 1;
        color[0].g = 0;
        color[0].b = 0;
        color[0].a = 1;
        color[1] = new ColorRGBA();
        color[1].r = 0;
        color[1].g = 1;
        color[1].b = 0;
        color[1].a = 1;
        color[2] = new ColorRGBA();
        color[2].r = 0;
        color[2].g = 0;
        color[2].b = 1;
        color[2].a = 1;
        int[] indices = { 0, 1, 2};

        t = new TriMesh("Triangle", verts, null, color, null, indices);
        t.setModelBound(new BoundingSphere());
        t.updateModelBound();
        System.out.println(t.getModelBound());
        cam.update();

        scene = new Node("3D Scene Node");
        scene.attachChild(t);
        cam.update();

        scene.updateGeometricState(0.0f, true);

    }

    /**
     * not used.
     *
     * @see com.jme.app.SimpleGame#reinit()
     */
    protected void reinit() {

    }

    /**
     * Not used.
     *
     * @see com.jme.app.SimpleGame#cleanup()
     */
    protected void cleanup() {

    }

}



Maybe that will help.

i got something to render. nice, thanks for the help. the bottom half of the screen is all messed up tho. but i will play with that myself and see what i can do.



i’ll also log onto the cvs and get the source so i can check some code out.



thanks again for all the help