Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
OpenGL using multiple classes
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Braindrool  
View profile   Translate to Translated (View Original)
 More options Aug 15 2012, 8:37 pm
From: Braindrool <cawehk...@gmail.com>
Date: Wed, 15 Aug 2012 17:37:03 -0700 (PDT)
Local: Wed, Aug 15 2012 8:37 pm
Subject: OpenGL using multiple classes

I've been programming for years, but I have very little experience with 3D
graphics. I thought OpenGL would be the most efficient in this project.
It's coming along alright, I am still studying the API and documentation.
But I have encountered a problem using multiple classes. For instance, here
I try to use a separate class for the player model. (Yes, currently it's
just a cube.)

Renderer:

Code:

package com.braindrool.bla;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView.Renderer;

public class BlaRenderer implements Renderer {

        int nrOfVertices;
        float A;
        Player player = new Player();

        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
                // TODO Auto-generated method stub

                gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
                gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

                gl.glEnable(GL10.GL_CULL_FACE);

                gl.glFrontFace(GL10.GL_CCW);
                gl.glCullFace(GL10.GL_BACK);

                gl.glClearColor(0.3f, 0.8f, 0.9f, 1);

        //      initTriangle();
                player.initPlayer();

        }

        public void onDrawFrame(GL10 gl) {
                // TODO Auto-generated method stub

                gl.glLoadIdentity();

                gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

                // gl.glRotatef(A * 2, 1f, 0f, 0f);
                // gl.glRotatef(A, 0f, 1f, 0f);
                //
                // gl.glColor4f(0.5f, 0, 0, 1);

                gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
                gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
                gl.glDrawElements(GL10.GL_TRIANGLES, nrOfVertices,
                                GL10.GL_UNSIGNED_SHORT, indexBuffer);
                // A++;

        }

        public void onSurfaceChanged(GL10 gl, int width, int height) {
                // TODO Auto-generated method stub
                gl.glViewport(0, 0, width, height);

        }

        private FloatBuffer vertexBuffer;
        private ShortBuffer indexBuffer;

        private FloatBuffer colorBuffer;

        private void initTriangle() {

                float[] coords = { 0, 0.5f, 0, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f,
                                0, 0, -0.5f };

                nrOfVertices = coords.length;

                ByteBuffer vbb = ByteBuffer.allocateDirect(nrOfVertices * 3 * 4);
                vbb.order(ByteOrder.nativeOrder());
                vertexBuffer = vbb.asFloatBuffer();

                ByteBuffer ibb = ByteBuffer.allocateDirect(nrOfVertices * 2);
                ibb.order(ByteOrder.nativeOrder());
                indexBuffer = ibb.asShortBuffer();

                ByteBuffer cbb = ByteBuffer.allocateDirect(4 * nrOfVertices * 4);
                cbb.order(ByteOrder.nativeOrder());
                colorBuffer = cbb.asFloatBuffer();

                float[] colors = { 1f, 0f, 0f, 1f, // point 1
                                0f, 1f, 0f, 1f, // point 2
                                0f, 0f, 1f, 1f, // point 3
                };

                short[] indices = new short[] {
                                // indices
                                0, 1, 2, 0, 2, 3, 0, 3, 1, 3, 1, 2

                };

                vertexBuffer.put(coords);
                indexBuffer.put(indices);
                colorBuffer.put(colors);

                vertexBuffer.position(0);
                indexBuffer.position(0);
                colorBuffer.position(0);

        }

}

And now the player class.

Code:

package com.braindrool.bla;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class Player extends BlaRenderer{

        private FloatBuffer vertexBuffer;
        private ShortBuffer indexBuffer;
        private FloatBuffer colorBuffer;
        private int nrOfVertices;
        float A;

        public void initPlayer() {

                float[] coords = {

                -0.5f, 0.5f, 0, // P0
                                -0.5f, 0, 0, // P1
                                0.5f, 0, 0, // P2
                                0.5f, 0.5f, 0, // P3
                                0.5f, 0.5f, 0.5f, // P4
                                -0.5f, 0.5f, 0.5f, // P5
                                -0.5f, 0, 0.5f, // P6
                                0.5f, 0, 0.5f // P7
                };

                nrOfVertices = coords.length;

                ByteBuffer vbb = ByteBuffer.allocateDirect(nrOfVertices * 4);
                vbb.order(ByteOrder.nativeOrder());
                vertexBuffer = vbb.asFloatBuffer();

                ByteBuffer ibb = ByteBuffer.allocate(nrOfVertices * 2);
                ibb.order(ByteOrder.nativeOrder());
                indexBuffer = ibb.asShortBuffer();

                ByteBuffer cbb = ByteBuffer.allocate(12 * 4);
                ibb.order(ByteOrder.nativeOrder());
                colorBuffer = cbb.asFloatBuffer();

                short[] indices = {

                0, 1, 2, 3, 0, 2, 0, 6, 1, 0, 5, 6, 5, 7, 6, 5, 4, 7, 4, 3, 7, 3, 2, 7

                };

                float[] colors = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1 };

                vertexBuffer.put(coords);
                indexBuffer.put(indices);
                colorBuffer.put(colors);

                vertexBuffer.position(0);
                indexBuffer.position(0);
                colorBuffer.position(0);

        }

}

It's a bit sloppy but meh.

The error:

Code:

Player player = new Player()

&

Code:

public class Player extends BlaRenderer{

Help appreciated!

~Braindrool


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Satya Komatineni  
View profile   Translate to Translated (View Original)
 More options Aug 16 2012, 8:38 am
From: Satya Komatineni <satya.komatin...@gmail.com>
Date: Thu, 16 Aug 2012 08:38:43 -0400
Local: Thurs, Aug 16 2012 8:38 am
Subject: Re: [android-developers] OpenGL using multiple classes
Hopefully you have a good reason to structure  your classes they way
you have done.

To start BlaRenderer is a proper derived class that will get called.
So this is a concrete class by itself.

Number 2, the player class looks more like a utilitiy class and hence
doesn't need to derive from BlaRenderer. In your code I don't see the
Player class playing the role of a renderer.

Number 3, BlaRenderer has a local variable pointing to a Player class.
So the variables of Player class are physically separate from the
variables of BlaRenderer. if your intention is to have the Player as a
utility class, then

1. Don't inherit from Renderer
2. Remove the local variables in the BlaRenderer which are now
controlled by Renderer

Hope that helps
http://satyakomatineni.com/android/training
http://satyakomatineni.com
http://androidbook.com
http://twitter.com/SatyaKomatineni


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Braindrool  
View profile  
 More options Aug 16 2012, 5:04 pm
From: Braindrool <cawehk...@gmail.com>
Date: Thu, 16 Aug 2012 14:04:49 -0700 (PDT)
Local: Thurs, Aug 16 2012 5:04 pm
Subject: Re: [android-developers] OpenGL using multiple classes

Don't mean to be a burden here, but think you could elaborate a bit about
how to fix? I'm new to Java, and so far I don't like it. But then again I
may just not be used to it.

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bob  
View profile  
 More options Aug 16 2012, 6:32 pm
From: bob <b...@coolfone.comze.com>
Date: Thu, 16 Aug 2012 15:32:59 -0700 (PDT)
Local: Thurs, Aug 16 2012 6:32 pm
Subject: Re: OpenGL using multiple classes

You have an infinite loop, and you're getting a stack overflow.

In BlaRenderer, you create a new Player object:

Player player = new Player();

Since it inherits from BlaRenderer, it tries to create a new Player object:

Player player = new Player();

Since it inherits from BlaRenderer, it tries to create a new Player object:

Player player = new Player();

This continues until you are out of stack space.  One solution:

Remove this line from BlaRenderer:

Player player = new Player();


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Braindrool  
View profile  
 More options Aug 16 2012, 6:48 pm
From: Braindrool <cawehk...@gmail.com>
Date: Thu, 16 Aug 2012 15:48:52 -0700 (PDT)
Local: Thurs, Aug 16 2012 6:48 pm
Subject: Re: OpenGL using multiple classes

I think you are overestimating my knowledge of Java. I don't quite
understand how to incorporate multiple classes. How do I include my
initPlayer() function?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Braindrool  
View profile  
 More options Aug 19 2012, 7:51 pm
From: Braindrool <cawehk...@gmail.com>
Date: Sun, 19 Aug 2012 16:51:42 -0700 (PDT)
Local: Sun, Aug 19 2012 7:51 pm
Subject: Re: OpenGL using multiple classes

Resolved.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »