OpenGL Spectrum, Only One Point Visible

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 1736 Views - Last Post: 21 March 2013 - 10:48 PM Rate Topic: -----

#16 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 207
  • View blog
  • Posts: 550
  • Joined: 12-July 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 20 March 2013 - 10:51 PM

In the code where you calculate the values in mPoints, it looks like you are assuming only vertices with a x coordinate between 0 and view.getWidth() and a y coordinate between 0 and view.getHeight() will be visible in the view.

This is wrong. Since you do not give OpenGL any matrixes, only vertices with a x coordinate between -1 and 1 and a y coordinate between -1 and 1 will be visible.
Was This Post Helpful? 0
  • +
  • -

#17 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 20 March 2013 - 10:56 PM

Hezekiah:
Oh!
How do i fix it? :)



:
Most of the function used in that tutorial-series is useless to me, because they do not exist in OpelGL ES
Was This Post Helpful? 0
  • +
  • -

#18 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 207
  • View blog
  • Posts: 550
  • Joined: 12-July 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 20 March 2013 - 11:06 PM

For mPoints[i * 6] and mPoints[i * 6 + 3], the calculation should be changed so that all values are between -1 and 1, not between 0 and view.getWidth().

For mPoints[i * 6 + 1] and mPoints[i * 6 + 4], the calculation should be changed so that all values are between -1 and 1, not between 0 and view.getHeight().

I agree that you should get to know OpenGL ES better, but I also think an OpenGL ES tutorial would be better than a desktop OpenGL tutorial (though I can't give you any suggestions).
Was This Post Helpful? 1
  • +
  • -

#19 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 20 March 2013 - 11:36 PM

Okay.
I just tried change the height and width to 1.0F and got this result
Attached Image

So, the calculation now looks like this:
    for (int i = 0; i < mBytes.length - 1; i++) {
      mPoints[i * 6] = 1.0f * i / (mBytes.length - 1);
      mPoints[i * 6 + 1] = 1.0f / 2 + ((byte) (mBytes[i] + 128)) * (1.0f / 3) / 128;
      mPoints[i * 6 + 2] = 0;
      mPoints[i * 6 + 3] = 1.0f * (i + 1) / (mBytes.length - 1);
      mPoints[i * 6 + 4] = 1.0f / 2 + ((byte) (mBytes[i + 1] + 128)) * (1.0f / 3) / 128;
      mPoints[i * 6 + 5] = 0;
    }


Do you happen to know what should do to move it so it start to the left? Not sure where to set -1.0F in my calculation. Will try some stuff.

And why dose the end to back to point 0,0?
Was This Post Helpful? 0
  • +
  • -

#20 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 207
  • View blog
  • Posts: 550
  • Joined: 12-July 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 20 March 2013 - 11:46 PM

You could use 2 as the width and height and then subtract 1 at the end of the calculation (to get from 0,2 to -1,1).
Was This Post Helpful? 1
  • +
  • -

#21 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 12:07 AM

Okay. Look better, but it dose not go all the way out to the horizontal edges. And it's very little when i put the phone in landscape-mode.
Can't i get the visible matrix or something?

This is what it looks like now in portrait-mode
Attached Image
Was This Post Helpful? 0
  • +
  • -

#22 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 207
  • View blog
  • Posts: 550
  • Joined: 12-July 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 02:04 AM

How do you set up the OpenGL viewport? Are you sure it covers the whole screen?

Edit: What do you see when you draw a GL_TRIANGLE_STRIP with vertices (1,1,0), (-1,1,0), (1,-1,0), (-1,-1,0)? That should draw a rectangle to cover the whole viewport.

This post has been edited by Hezekiah: 21 March 2013 - 02:33 AM

Was This Post Helpful? 0
  • +
  • -

#23 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 03:07 AM

View PostEndLessMind, on 21 March 2013 - 02:56 AM, said:

:
Most of the function used in that tutorial-series is useless to me, because they do not exist in OpelGL ES

You're not understanding me. You need to understand OpenGL itself. I know that OpenGL ES is a very stripped down version of OpenGL and a lot of what you will be reading is not part of ES; you need to get the theory nailed, this is your first attempt at ES and it's copied.

Anyway, the choice is yours. Tweaking values until it works without understanding is a recipe for disaster.

This post has been edited by ButchDean: 21 March 2013 - 03:07 AM

Was This Post Helpful? 0
  • +
  • -

#24 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 10:09 AM

Hezekiah
This is what i see: (The camera is set to 0f, 0f, -5f : gl.glTranslatef(0.0f, 0.0f, -5.0f); )

Portrait:
Attached Image

Landscape:
Attached Image

This is how i handle SurfaceChange
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    mWidth = (float)width; 
    mHeight = (float)height;

	gl.glViewport(0, 0, width, height); 
	gl.glMatrixMode(GL10.GL_PROJECTION);
	gl.glLoadIdentity();
	gl.glEnable(gl.GL_CULL_FACE);
	
	GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);
	gl.glMatrixMode(GL10.GL_MODELVIEW);
	gl.glLoadIdentity(); 
}



Oh, okay.
I'll look at that, but the best way for me to learn is to try and make mistakes.
We all learn from our mistakes.

This post has been edited by EndLessMind: 21 March 2013 - 10:12 AM

Was This Post Helpful? 0
  • +
  • -

#25 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 207
  • View blog
  • Posts: 550
  • Joined: 12-July 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 11:59 AM

You don't need any 3D here, so it will probably be easiest to not use any matrices (or at least leave them as identity matrices).
GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);

This line creates a perspective projection matrix. It causes objects further away from the camera to look smaller. You don't want that.

If you only remove the line above, however, nothing will be drawn anymore. This is because as I said earlier, all coordinates must be between -1 and 1. The glTranslatef call causes all your vertices to have a z coordinate of -5. Simply remove the glTranslatef call to solve this.

Edit: This is why it would be better to have a good understanding of OpenGL. These mistakes seem obvious once you understand how everything works.

This post has been edited by Hezekiah: 21 March 2013 - 12:02 PM

Was This Post Helpful? 1
  • +
  • -

#26 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 12:08 PM

Removing gl.glTranslatef(0.0f, 0.0f, -5.0f); dose also cause nothing to be drawn
Was This Post Helpful? 0
  • +
  • -

#27 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 207
  • View blog
  • Posts: 550
  • Joined: 12-July 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 12:10 PM

You have to remove that and the gluPerspective call.
Was This Post Helpful? 1
  • +
  • -

#28 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 12:42 PM

Thanks, that worked :)
Can you help me with one last thing? :)
I've got this other algorithm that takes that scope and makes it a circle.
In canvas, it looks like this:
Attached Image

But when i take that algorithm and change it like the last one, then i get this in OpenGL
Attached Image

Sure it's a cool and complex shape, but not what i'm looking for :P

For canvas, i use this:
  @Override
  public void onRender(Canvas canvas, AudioData data, Rect rect)
  {
    if(mCycleColor)
    {
      cycleColor();
    }

    for (int i = 0; i < data.bytes.length - 1; i++) {
        // Calculate dbValue
    	float[] cartPoint = null;
    	if (i < data.bytes.length -1) {
     float[] cartPoint_deff = {
          (float)i / (data.bytes.length - 1),
          rect.height() / 2 + ((byte) (data.bytes[i] + 128)) * (rect.height() / 2) / 256
      };
     cartPoint = cartPoint_deff;
    	}
     else {
         float[] cartPoint_deff = {
                 (float)i / (data.bytes.length - 1),
                 rect.height() / 2 + ((byte) (data.bytes[0] + 128)) * (rect.height() / 2) / 256
             };
            cartPoint = cartPoint_deff;
    	}
      float[] polarPoint = toPolar(cartPoint, rect);
      mPoints[i * 4] = polarPoint[0];
      mPoints[i * 4 + 1] = polarPoint[1];
      float[] cartPoint2 = null;
      if (i < data.bytes.length -1) {
      float[] cartPoint2_deff = {
          (float)(i + 1) / (data.bytes.length - 1),
          rect.height() / 2 + ((byte) (data.bytes[i + 1] + 128)) * (rect.height() / 2) / 128
      };
      cartPoint2 = cartPoint2_deff;
      } else {
          float[] cartPoint2_deff = {
                  (float)(i + 1) / (data.bytes.length - 1),
                  rect.height() / 2 + ((byte) (data.bytes[0 + 1] + 128)) * (rect.height() / 2) / 128
              };
          cartPoint2 = cartPoint2_deff;
      }
      float[] polarPoint2 = toPolar(cartPoint2, rect);
      mPoints[i * 4 + 2] = polarPoint2[0];
      mPoints[i * 4 + 3] = polarPoint2[1];
    }
    mBackPaint = new Paint();
    mBackPaint.setAntiAlias(true);
    mBackPaint.setColor(Color.parseColor("#4A1D1D1D"));
      canvas.drawPaint(mBackPaint); 
    canvas.drawLines(mPoints, mPaint);

    // Controls the pulsing rate
    modulation += 0.08;
  }

  @Override
  public void onRender(Canvas canvas, FFTData data, Rect rect)
  {
    // Do nothing, we only display audio data
  }

  float modulation = 0;
  float modulationStrength = 0.4f; // 0-1
  float aggresive = 0.33f;
  private float[] toPolar(float[] cartesian, Rect rect)
  {
    double cX = rect.width()/2;
    double cY = rect.height()/2;
    double angle = (cartesian[0]) * 2 * Math.PI;
    double radius = ((rect.height()/2) * (1 - aggresive) + aggresive * cartesian[1]/2) * ((1 - modulationStrength) + modulationStrength * (1 + Math.sin(modulation)) / 2);
    float[] out = {
        (float)(cX + radius * Math.sin(angle)),
        (float)(cY + radius * Math.cos(angle))
    };
    return out;
  }


So i changed it into this:
@Override
public void onDrawFrame(GL10 gl) {
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
	//Log.d("TAAFFAAFA", gl.glGetError() + "");
	gl.glLoadIdentity();
//	gl.glTranslatef(0.0f, 0.0f, -5.0f);

    if (mBytes != null) {
    	if (mPoints == null || mPoints.length < mBytes.length * 6) {
	        mPoints = new float[mBytes.length * 6];
	      }
    	
	 if (mPoints != null) {
		// Calculate points for line
		 
		 
		 
		 for (int i = 0; i < mBytes.length - 1; i++) {
		        // Calculate dbValue
		    	float[] cartPoint = null;
		    	if (i < mBytes.length -1) {
		     float[] cartPoint_deff = {
		          (float)i / (mBytes.length - 1),
		          (2.0f / 2 + ((byte) (mBytes[i] + 128)) * (2.0f / 2) / 256) 
		      };
		     cartPoint = cartPoint_deff;
		    	}
		     else {
		         float[] cartPoint_deff = {
		                 (float)i / (mBytes.length - 1),
		                 (2.0f / 2 + ((byte) (mBytes[0] + 128)) * (2.0f / 2) / 256) 
		             };
		            cartPoint = cartPoint_deff;
		    	}
		      float[] polarPoint = toPolar(cartPoint);
		      mPoints[i * 4] = polarPoint[0]  - 1.0f;
		      mPoints[i * 4 + 1] = polarPoint[1]  - 1.0f;
		      mPoints[i * 4 + 2] = 0;
		      float[] cartPoint2 = null;
		      if (i < mBytes.length -1) {
		      float[] cartPoint2_deff = {
		          (float)(i + 1) / (mBytes.length - 1),
		          (2.0f / 2 + ((byte) (mBytes[i + 1] + 128)) * (2.0f / 2) / 128) 
		      };
		      cartPoint2 = cartPoint2_deff;
		      } else {
		          float[] cartPoint2_deff = {
		                  (float)(i + 1) / (mBytes.length - 1),
		                  (2.0f / 2 + ((byte) (mBytes[0 + 1] + 128)) * (2.0f / 2) / 128) 
		              };
		          cartPoint2 = cartPoint2_deff;
		      }
		      float[] polarPoint2 = toPolar(cartPoint2);
		      mPoints[i * 4 + 3] = polarPoint2[0]  - 1.0f;
		      mPoints[i * 4 + 4] = polarPoint2[1]  - 1.0f;
		      mPoints[i * 4 + 5] = 0;
		    }
		 
		 
    draw(gl);
	 }
    }

}

float modulation = 0;
float modulationStrength = 0.4f; // 0-1
float aggresive = 0.33f;

private float[] toPolar(float[] cartesian)
{
  double cX = 2.0f/2;
  double cY = 2.0f/2;
  double angle = (cartesian[0]) * 2 * Math.PI;
  double radius = ((2.0f/2) * (1 - aggresive) + aggresive * cartesian[1]/2) * ((1 - modulationStrength) + modulationStrength * (1 + Math.sin(modulation)) / 2) ;
  float[] out = {
      (float)(cX + radius * Math.sin(angle)) ,
      (float)(cY + radius * Math.cos(angle)) 
  };
  return out;
}


All heights and widths are changed to 2.0F, and then i use "-1.0f" when i add the floats to the array.

Thanks in advance

This post has been edited by EndLessMind: 21 March 2013 - 01:13 PM

Was This Post Helpful? 0
  • +
  • -

#29 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 207
  • View blog
  • Posts: 550
  • Joined: 12-July 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 02:23 PM

In the first snippet you use 4 array elements per line segment (2 vertices * 2 components), while in the second snippet you use 6 (2 vertices * 3 components). The problem is that when you copied the code for the second version, you left the indices as [i * 4 + x], instead of making them [i * 6 + x] like you had for the linear version.
Was This Post Helpful? 1
  • +
  • -

#30 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 02:33 PM

Oh. Lol. How could i not see that? Hah. Thanks man
I know that it's all stretched out because the device-display is in a widescreen-format,
and i know then i can make in un-stretched by using glTranslatef and gluPerspective.
But, is there an other way to do this?
No that i mind, because the different visuals is going to be in a sub-renderer later, so i can just add gluPerspective and glTranslatef to that one.
But, i just wanna know.

Again, thanks! :)
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3