[android-developers] Re: How to test OpenGL?
I created a new thread for this topic, with better examples and screen shots. It is at http://groups.google.com/group/android-developers/browse_thread/thread/42efe5ae8acbc308 On Aug 4, 10:50 am, SChaser wrote: > On Aug 3, 10:06 pm, Robert Green wrote:> Have you tried > different values of gl.glLineWidthx()? 0x1 is 1 in > > hex, which, given in fixed converted to float = 0.1 = super, > > super, super tiny. I'd start with 65536 (0x if you really like > > using hex to represent FP) and see how it does. > > Yeah, I have since my last post. If I use a very wide line (, it does > show up on the emulator, as a wide (not 1 px) line. On the phone, it > still shows up as a 1px wide line. Go figure. > > There is something else fishy on the emulator that hints at an issue > in the transformations - when I do make a huge line, it isn't in the > right place. Instead of having an X in the middle of the screen (among > other things), I have a vertical line that extends from somewhat below > the middle of the screen to the top of the screen. > > Code is now: > public void onDrawFrame(GL10 gl) { > float fOrthoScale = 1; > int lineWidth = 0x1; > _hgt2width = (float) MyApp._width / MyApp._height; > gl.glClearColor(0,0,.2f, 1f); > gl.glDisable(GL10.GL_CULL_FACE); > gl.glShadeModel(GL10.GL_FLAT); > gl.glDisable(GL10.GL_DEPTH_TEST); > gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); > // gl.glViewport(0, 0, MyApp._width/2, MyApp._height/2); > gl.glMatrixMode(GL10.GL_PROJECTION); > gl.glLoadIdentity(); > GLU.gluOrtho2D(gl, -_hgt2width*fOrthoScale, > _hgt2width*fOrthoScale, -1*fOrthoScale, 1*fOrthoScale); > gl.glMatrixMode(GL10.GL_MODELVIEW); > gl.glLoadIdentity(); > // gl.glEnable(GL10.GL_BLEND); > gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); > gl.glEnable(GL10.GL_LINE_SMOOTH); > gl.glDisableClientState(GL10.GL_COLOR_ARRAY); > > gl.glScalef(1, _hgt2width, 1); > // gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); > gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); > > float lscale = .002f*MyApp._curScale; > > gl.glPushMatrix(); > gl.glColor4f(1f, 1f, 0f, 1f); > gl.glTranslatef(.375f, .5f, 0f); > gl.glRotatef(30, 0, 0, 1); > gl.glScalef( lscale, lscale, 1f); > gl.glVertexPointer(2, GL10.GL_FIXED, 0, _lineVertices); > gl.glLineWidthx(lineWidth); > drawArrays(gl); > gl.glPopMatrix(); > > gl.glPushMatrix(); > gl.glColor4f(1f, 1f, 1f, 1.0f); > gl.glScalef( lscale*8, lscale*8, 1f); > gl.glVertexPointer(2, GL10.GL_FIXED, 0, _lineVertices); > gl.glLineWidthx(lineWidth); > drawArrays(gl); > gl.glPopMatrix(); > > } > void drawArrays(GL10 gl) { > gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, 5); //small square > gl.glDrawArrays(GL10.GL_LINE_STRIP, 5, 5); //medium square > gl.glDrawArrays(GL10.GL_LINE_STRIP, 10, 5);//large square > gl.glDrawArrays(GL10.GL_LINE_STRIP, 15, 2);//x axis > gl.glDrawArrays(GL10.GL_LINE_STRIP, 17, 2);//y axis > gl.glDrawArrays(GL10.GL_LINE_STRIP, 19, 2);//X half > gl.glDrawArrays(GL10.GL_LINE_STRIP, 21, 2);//X half > } > > void makeLines() { > int hlf = 0x08000; > int one = 0x1; > int sml = one/8; > int med = one*8; > int big = 0x1000; > Log.d("===jrm", String.format("one:%x big:%x", one, big)); > int vertices[] = { > -sml , sml, //0 start square - scale 1/10 > sml , sml, //1 > sml , -sml, //2 > -sml , -sml, //3 > -sml , sml, //4 > > -one , one, //5 start square - scale 1 > one , one, //6 > one , -one, //7 > -one , -one, //8 > -one , one, //9 > > -med , med, //10 start square - scale 10 > med , med, //11 > med , -med, //12 > -med , -med, //13 > -med , med, //14 > > -big , 0, //15 start coord axes over huge area > big , 0, //16 > > 0 , big, //17 > 0 , -big, //18 > > -big , -big, //19 start X over huge dimensions > big , big, //20 > > -big , big, //21 > big , -big, //22 > med , one // BUT? Without this line, blows up > if openGL debug is enabled > > }; > this.numLines = vertices.length/2; > > ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4); > vbb.order(ByteOrder.nativeOrder()); > _lineVertices = vbb.asIntBuffer(); > _lineVertices.put(vertices); > _lineVertices.position(0); > } -- You received this message because you are subscribed to the Google Groups "Android De
[android-developers] Re: How to test OpenGL?
On Aug 3, 10:06 pm, Robert Green wrote: > Have you tried different values of gl.glLineWidthx()? 0x1 is 1 in > hex, which, given in fixed converted to float = 0.1 = super, > super, super tiny. I'd start with 65536 (0x if you really like > using hex to represent FP) and see how it does. > Yeah, I have since my last post. If I use a very wide line (, it does show up on the emulator, as a wide (not 1 px) line. On the phone, it still shows up as a 1px wide line. Go figure. There is something else fishy on the emulator that hints at an issue in the transformations - when I do make a huge line, it isn't in the right place. Instead of having an X in the middle of the screen (among other things), I have a vertical line that extends from somewhat below the middle of the screen to the top of the screen. Code is now: public void onDrawFrame(GL10 gl) { float fOrthoScale = 1; int lineWidth = 0x1; _hgt2width = (float) MyApp._width / MyApp._height; gl.glClearColor(0,0,.2f, 1f); gl.glDisable(GL10.GL_CULL_FACE); gl.glShadeModel(GL10.GL_FLAT); gl.glDisable(GL10.GL_DEPTH_TEST); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); //gl.glViewport(0, 0, MyApp._width/2, MyApp._height/2); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluOrtho2D(gl, -_hgt2width*fOrthoScale, _hgt2width*fOrthoScale, -1*fOrthoScale, 1*fOrthoScale); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); //gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL10.GL_LINE_SMOOTH); gl.glDisableClientState(GL10.GL_COLOR_ARRAY); gl.glScalef(1, _hgt2width, 1); //gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); float lscale = .002f*MyApp._curScale; gl.glPushMatrix(); gl.glColor4f(1f, 1f, 0f, 1f); gl.glTranslatef(.375f, .5f, 0f); gl.glRotatef(30, 0, 0, 1); gl.glScalef( lscale, lscale, 1f); gl.glVertexPointer(2, GL10.GL_FIXED, 0, _lineVertices); gl.glLineWidthx(lineWidth); drawArrays(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glColor4f(1f, 1f, 1f, 1.0f); gl.glScalef( lscale*8, lscale*8, 1f); gl.glVertexPointer(2, GL10.GL_FIXED, 0, _lineVertices); gl.glLineWidthx(lineWidth); drawArrays(gl); gl.glPopMatrix(); } void drawArrays(GL10 gl) { gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, 5); //small square gl.glDrawArrays(GL10.GL_LINE_STRIP, 5, 5); //medium square gl.glDrawArrays(GL10.GL_LINE_STRIP, 10, 5);//large square gl.glDrawArrays(GL10.GL_LINE_STRIP, 15, 2);//x axis gl.glDrawArrays(GL10.GL_LINE_STRIP, 17, 2);//y axis gl.glDrawArrays(GL10.GL_LINE_STRIP, 19, 2);//X half gl.glDrawArrays(GL10.GL_LINE_STRIP, 21, 2);//X half } void makeLines() { int hlf = 0x08000; int one = 0x1; int sml = one/8; int med = one*8; int big = 0x1000; Log.d("===jrm", String.format("one:%x big:%x", one, big)); int vertices[] = { -sml , sml,//0 start square - scale 1/10 sml , sml,//1 sml ,-sml,//2 -sml ,-sml,//3 -sml , sml,//4 -one , one,//5 start square - scale 1 one , one,//6 one ,-one,//7 -one ,-one,//8 -one , one,//9 -med , med,//10 start square - scale 10 med , med,//11 med ,-med,//12 -med ,-med,//13 -med , med,//14 -big , 0,//15 start coord axes over huge area big , 0,//16 0 , big,//17 0 ,-big,//18 -big ,-big,//19 start X over huge dimensions big , big,//20 -big , big,//21 big ,-big,//22 med , one // BUT? Without this line, blows up if openGL debug is enabled }; this.numLines = vertices.length/2; ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4); vbb.order(ByteOrder.nativeOrder()); _lineVertices = vbb.asIntBuffer(); _lineVertices.put(vertices); _lineVertices.position(0); } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to test OpenGL?
Have you tried different values of gl.glLineWidthx()? 0x1 is 1 in hex, which, given in fixed converted to float = 0.1 = super, super, super tiny. I'd start with 65536 (0x if you really like using hex to represent FP) and see how it does. On Aug 3, 8:31 pm, SChaser wrote: > On Aug 3, 4:33 pm, Indicator Veritatis wrote: > > > But I am surprised no one has mentioned: your settings for glOrtho's > > near_val and far_val are odd, to say the least. The default is exactly > > the other way around with near_val=-1.0 and far_val=+1.0. Your values > > put the near plane behind the viewer, but the far plane in front. Is > > this really what you want? > > Thanks for pointing this out. I have reversed them (no effect) as a > result of your suggestion. > > I threw them in at the last moment, well into this thread. Originally > they were at 0,0 (I'd drawing in 2D), but when I turned on debugging, > it showed me this was causing a divide by zero (duh - if I'd looked at > the resulting transform matrix I'd have seen that). So I just added > the values, and got them backwards. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to test OpenGL?
On Aug 3, 4:33 pm, Indicator Veritatis wrote: > But I am surprised no one has mentioned: your settings for glOrtho's > near_val and far_val are odd, to say the least. The default is exactly > the other way around with near_val=-1.0 and far_val=+1.0. Your values > put the near plane behind the viewer, but the far plane in front. Is > this really what you want? Thanks for pointing this out. I have reversed them (no effect) as a result of your suggestion. I threw them in at the last moment, well into this thread. Originally they were at 0,0 (I'd drawing in 2D), but when I turned on debugging, it showed me this was causing a divide by zero (duh - if I'd looked at the resulting transform matrix I'd have seen that). So I just added the values, and got them backwards. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to test OpenGL?
Robert Green, thanks again for your informative answer. I added the MODELVIEW mode right after setting the viewport, and did a loadIdentity after that. No change, but I agree its the correct thing to do. Still zero lines visible on the emulator (even when I scale up its display). Looks fine on the G1. Off to read the manuals again ;-( Per your question: "gl.glScalef(1, _hgt2width, 1); float lscale = .002f*MyApp._curScale; It could be that I just don't understand what this is supposed to do but magic multipliers like .002 never look good to me when you're having issues with drawing precision." I am drawing in a geographical coordinate space, not pixel space. So the scaling is used to transform from that space to the viewing space. In my geographical space, my coordinates are in (projected) lat/long specified with higher precision than even float can deal with (which, fortunately, isn't a problem with this app). My test case uses simple coordinates, but I left in the same scaling as in the real app. "// ditch the fixed point (it's only faster on first-gen devices and only in certain cases)" For now, I'll keep it because a bunch of code is in it, and I am testing on a first gen device. // now if you want a line 1px wide on the 10th line, draw a line with x on 9.5f I just want my lines to show up, and my reading of the openGl documents indicates that they should, if drawn with a line width of 1, no matter where I put them. Of course, offsetting them from pixel edges would be a good idea, except I am not drawing in pixel coordinate space. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to test OpenGL?
Others have already pointed out problems, potential and verifiable. But I am surprised no one has mentioned: your settings for glOrtho's near_val and far_val are odd, to say the least. The default is exactly the other way around with near_val=-1.0 and far_val=+1.0. Your values put the near plane behind the viewer, but the far plane in front. Is this really what you want? On Aug 2, 8:47 pm, SChaser wrote: > Source code is below. > > Robert Green provides some helpful information, for which I am > thankful. > > However, I am not clear on two of the points. > > I currently have the situation where no lines at all show on the > emulator (the background color does) and things work perfectly on the > G1. > > On Aug 2, 11:26 am, Robert Green wrote: > > > > 1) You are in a native resolution to the screen you're rendering on > > (turn all the density and screen-size stuff on in the manifest to > > avoid compat mode) > > Are these the attributes on the "support-screens" tag? I did not have > that tag, but adding it and turning on all the attributes in the check- > boxes did not solve the problem. > > > 2) You draw the lines centered on their pixel, so they look a half > > pixel off. > > -- To draw a horizontal line across the top row of pixels, you need to > > make the line with 1.0f and have y be 0.5f (because it will draw from > > 0 to 1 that way) > > I am drawing in fixed point projection(?) space, so the relationship > of the lines to pixels is not clear. Also, I don't want to have to > redraw the lines when the scale changes - I want to be able to zoom > and pan easily. Is there a way to achieve that and have the lines > show? > > > 3) Make sure you don't have any z-fighting. Drawing 2 things on the > > exact same plane with depth-test turned on causes bad results on many > > opengl implementations. > > Depth test turned off. I'm doing 2D only, so I think I'm clear there. > > Again, thanks for the help. > > CODE SNIPS == > > - Create glSurfaceView --- > private GLSurfaceView makeGLSurfaceView(GLSurfaceView.Renderer > renderer, Context context) { > GLSurfaceView view = new GLSurfaceView(context); > view.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR | > GLSurfaceView.DEBUG_LOG_GL_CALLS); > view.setEGLConfigChooser(false); > if ( renderer != null ) { > view.setRenderer(renderer); > view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); > } > view.getHolder().setFormat(PixelFormat.OPAQUE); > return view; > } // make gl surface view > > onDrawFrame -- > > // Everything stuffed into onDrawFrame to make it easy to read on > forum > @Override > public void onDrawFrame(GL10 gl) { > gl.glClearColor(0,0,.2f, 1f); > gl.glDisable(GL10.GL_CULL_FACE); > gl.glShadeModel(GL10.GL_FLAT); > gl.glDisable(GL10.GL_DEPTH_TEST); > gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); > gl.glMatrixMode(GL10.GL_PROJECTION); > gl.glLoadIdentity(); > gl.glViewport(0, 0, MyApp._width, MyApp._height); > gl.glEnable(GL10.GL_BLEND); > gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); > gl.glEnable(GL10.GL_LINE_SMOOTH); > gl.glDisableClientState(GL10.GL_COLOR_ARRAY); > _hgt2width = (float) MyApp._width / MyApp._height; > gl.glOrthof(-_hgt2width, _hgt2width, -1, 1, 1, -1); > > gl.glScalef(1, _hgt2width, 1); > gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); > > float lscale = .002f*MyApp._curScale; > > gl.glPushMatrix(); > gl.glColor4f(1f, 1f, 0f, 1f); > > gl.glTranslatef(.375f, .5f, 0f); > gl.glScalef( lscale, lscale, 1f); > gl.glVertexPointer(2, GL10.GL_FIXED, 0, _lineVertices); > gl.glLineWidthx(0x1); > drawArrays(gl); > gl.glPopMatrix(); > > gl.glPushMatrix(); > gl.glColor4f(1f, 1f, 1f, 1.0f); > gl.glScalef( lscale*8, lscale*8, 1f); > gl.glVertexPointer(2, GL10.GL_FIXED, 0, _lineVertices); > gl.glLineWidthx(0x1); > drawArrays(gl); > gl.glPopMatrix(); > > } > void drawArrays(GL10 gl) { > gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, 5); //small square > gl.glDrawArrays(GL10.GL_LINE_STRIP, 5, 5); //medium square > gl.glDrawArrays(GL10.GL_LINE_STRIP, 10, 5);//large square > gl.glDrawArrays(GL10.GL_LINE_STRIP, 15, 2);//x axis > gl.glDrawArrays(GL10.GL_LINE_STRIP, 17, 2);//y axis > gl.glDrawArrays(GL10.GL_LINE_STRIP, 19, 2);//X half > gl.glDrawArrays(GL10.GL_LINE_STRIP, 21, 2);//X half > } > > void makeLines() { > int hlf = 0x08000; > int one = 0x1+hlf; > int sml = one/8; > int ten = one; > int big = 0x4000; > Log.d("===jrm", String.format("one:%x big:%x", one, big)); > int vertices[] = { > -sml , sml, //0 start square - scale 1/10 > sml , sml, //1 > sml , -sml, //2 > -sml , -sml, //3 > -sml , sml, //4 > >
[android-developers] Re: How to test OpenGL?
My answer is about this line in particular: > ten , one // BUT? Without this line, blows up > if openGL debug is enabled I had problems using the OpenGL debug flag too, due to using buffers (but my problems were because my buffers were not direct, so no harm there). Where is makeLines() called anyway? Or did I miss the call? If you call makeLines() only once (i'm assuming this because I don't know where you make the call) you may have to call _lineVertices.position(0) before you use drawArrays() the second time. On Aug 3, 8:09 am, Robert Green wrote: > It would seem to me that you seek pixel perfect drawing but your code > doesn't look pixel perfect at all, which is why you're having problems > IMO. > > Problem stuff: > > ... in projection matrix ... > _hgt2width = (float) MyApp._width / MyApp._height; > gl.glOrthof(-_hgt2width, _hgt2width, -1, 1, 1, -1); > > gl.glScalef(1, _hgt2width, 1); > > float lscale = .002f*MyApp._curScale; > > It could be that I just don't understand what this is supposed to do > but magic multipliers like .002 never look good to me when you're > having issues with drawing precision. > > Here's what I'd do: > > gl.glMatrixMode(GL10.GL_PROJECTION); > gl.glOrthof(0, MyApp._width, MyApp._height, 0, 1, -1); > // now you can draw anywhere in your viewport pixel perfect > orthographically. > gl.glMatrixMode(GL10.GL_MODELVIEW); > // ditch the fixed point (it's only faster on first-gen devices and > only in certain cases) > // now if you want a line 1px wide on the 10th line, draw a line with > x on 9.5f > > Just be aware that you will need to figure out different relative > positions to draw at given different resolution screens if you wish to > remain pixel perfect. The other alternative is to stretch a fixed > drawing area, like 320x480 to the other screen sizes. All you have to > do to do that is set your orthof to those dimensions instead of the > real screen dimensions - but you'll lose pixel-perfectness on anything > that isn't that res. > > I didn't see you switching to your modelview anywhere in your code. > If you're not doing that, you're going to want to use that matrix mode > to draw. Projection should only be used to set the orthographic or > perspective projection and no more. > > On Aug 2, 10:47 pm, SChaser wrote:> Source code is > below. > > > Robert Green provides some helpful information, for which I am > > thankful. > > > However, I am not clear on two of the points. > > > I currently have the situation where no lines at all show on the > > emulator (the background color does) and things work perfectly on the > > G1. > > > On Aug 2, 11:26 am, Robert Green wrote: > > > > > > 1) You are in a native resolution to the screen you're rendering on > > > (turn all the density and screen-size stuff on in the manifest to > > > avoid compat mode) > > > Are these the attributes on the "support-screens" tag? I did not have > > that tag, but adding it and turning on all the attributes in the check- > > boxes did not solve the problem. > > > > 2) You draw the lines centered on their pixel, so they look a half > > > pixel off. > > > -- To draw a horizontal line across the top row of pixels, you need to > > > make the line with 1.0f and have y be 0.5f (because it will draw from > > > 0 to 1 that way) > > > I am drawing in fixed point projection(?) space, so the relationship > > of the lines to pixels is not clear. Also, I don't want to have to > > redraw the lines when the scale changes - I want to be able to zoom > > and pan easily. Is there a way to achieve that and have the lines > > show? > > > > 3) Make sure you don't have any z-fighting. Drawing 2 things on the > > > exact same plane with depth-test turned on causes bad results on many > > > opengl implementations. > > > Depth test turned off. I'm doing 2D only, so I think I'm clear there. > > > Again, thanks for the help. > > > CODE SNIPS == > > > - Create glSurfaceView --- > > private GLSurfaceView makeGLSurfaceView(GLSurfaceView.Renderer > > renderer, Context context) { > > GLSurfaceView view = new GLSurfaceView(context); > > view.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR | > > GLSurfaceView.DEBUG_LOG_GL_CALLS); > > view.setEGLConfigChooser(false); > > if ( renderer != null ) { > > view.setRenderer(renderer); > > view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); > > } > > view.getHolder().setFormat(PixelFormat.OPAQUE); > > return view; > > } // make gl surface view > > > onDrawFrame -- > > > // Everything stuffed into onDrawFrame to make it easy to read on > > forum > > @Override > > public void onDrawFrame(GL10 gl) { > > gl.glClearColor(0,0,.2f, 1f); > > gl.glDisable(GL10.GL_CULL_FACE); > > gl.glShadeModel(GL10.GL_FLAT); > > gl.glDisable(GL10.GL_DEPTH_TEST); > > gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); > > gl.glMatrixMo
[android-developers] Re: How to test OpenGL?
I'd say that an important point is that the emulator uses a software OpenGL renderer, while virtually every handset in the wild does OpenGL in hardware. In my experience, you just cannot rely on the emulator to accurately render OpenGL as a hardware device would. The emulator is "sufficient to test code for correctness," as SChaser said, but it is not a pixel-perfect image of what you'll see on a handset. Most of the time, it's pretty close, but if you're seeing something funny you really need to test it on hardware before you go chasing through your code. Something else you've probably noticed is that the emulator's OpenGL is SLOW. I know, the emulator is slow anyway, but the OpenGL seems to be the worst part. Again, the emulator should generally show you *whether* your OGL code runs, but not how well or how fast it runs. So as a starting point, you need at least one handset to test on, and the G1 is probably as good of a "reference" set as any. Unfortunately, there are also issues with how different hardware renders the same OpenGL scene - I've chased plenty of these myself. My advice is that you really could do with at least two handsets for testing OpenGL: two different resolutions (say HVGA and WVGA), from two different manufacturers. So a G1 and Droid/Milestone would be a good pair, for example. The question is, does the budget for your project justify that? String My experience over the past year On Aug 2, 8:07 pm, Bob Kerns wrote: > Robert Green's reply gives some specific points I couldn't because I'm > not really an OpenGL person myself, and definitely illustrates how > rendering can vary. > > But while I certainly would NOT expect identical results from > different rendering engines, it does sound to me like the differences > you note go beyond what I'd expect from my somewhat limited > experience, and the extremely large coordinates does strike me as a > point of suspicion. > > On Aug 2, 10:14 am, SChaser wrote: > > > > > It is entirely possible that I am doing something confused (not being > > that much of an OGL person), but even then, I would expect to see the > > same results on the emulator and the G1. In answer to another > > question, the demos work fine on the emulator. > > > Is it possible that disappearing lines are caused by the emulator > > pixels not matching exactly the Windows pixels to which they are > > ultimately rendered? > > > The varying width lines didn't appear until I used extremely large > > (but within the FP range) coordinates on a few lines. > > > I'll post the code when I get home and have access to it. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to test OpenGL?
It would seem to me that you seek pixel perfect drawing but your code doesn't look pixel perfect at all, which is why you're having problems IMO. Problem stuff: ... in projection matrix ... _hgt2width = (float) MyApp._width / MyApp._height; gl.glOrthof(-_hgt2width, _hgt2width, -1, 1, 1, -1); gl.glScalef(1, _hgt2width, 1); float lscale = .002f*MyApp._curScale; It could be that I just don't understand what this is supposed to do but magic multipliers like .002 never look good to me when you're having issues with drawing precision. Here's what I'd do: gl.glMatrixMode(GL10.GL_PROJECTION); gl.glOrthof(0, MyApp._width, MyApp._height, 0, 1, -1); // now you can draw anywhere in your viewport pixel perfect orthographically. gl.glMatrixMode(GL10.GL_MODELVIEW); // ditch the fixed point (it's only faster on first-gen devices and only in certain cases) // now if you want a line 1px wide on the 10th line, draw a line with x on 9.5f Just be aware that you will need to figure out different relative positions to draw at given different resolution screens if you wish to remain pixel perfect. The other alternative is to stretch a fixed drawing area, like 320x480 to the other screen sizes. All you have to do to do that is set your orthof to those dimensions instead of the real screen dimensions - but you'll lose pixel-perfectness on anything that isn't that res. I didn't see you switching to your modelview anywhere in your code. If you're not doing that, you're going to want to use that matrix mode to draw. Projection should only be used to set the orthographic or perspective projection and no more. On Aug 2, 10:47 pm, SChaser wrote: > Source code is below. > > Robert Green provides some helpful information, for which I am > thankful. > > However, I am not clear on two of the points. > > I currently have the situation where no lines at all show on the > emulator (the background color does) and things work perfectly on the > G1. > > On Aug 2, 11:26 am, Robert Green wrote: > > > > 1) You are in a native resolution to the screen you're rendering on > > (turn all the density and screen-size stuff on in the manifest to > > avoid compat mode) > > Are these the attributes on the "support-screens" tag? I did not have > that tag, but adding it and turning on all the attributes in the check- > boxes did not solve the problem. > > > 2) You draw the lines centered on their pixel, so they look a half > > pixel off. > > -- To draw a horizontal line across the top row of pixels, you need to > > make the line with 1.0f and have y be 0.5f (because it will draw from > > 0 to 1 that way) > > I am drawing in fixed point projection(?) space, so the relationship > of the lines to pixels is not clear. Also, I don't want to have to > redraw the lines when the scale changes - I want to be able to zoom > and pan easily. Is there a way to achieve that and have the lines > show? > > > 3) Make sure you don't have any z-fighting. Drawing 2 things on the > > exact same plane with depth-test turned on causes bad results on many > > opengl implementations. > > Depth test turned off. I'm doing 2D only, so I think I'm clear there. > > Again, thanks for the help. > > CODE SNIPS == > > - Create glSurfaceView --- > private GLSurfaceView makeGLSurfaceView(GLSurfaceView.Renderer > renderer, Context context) { > GLSurfaceView view = new GLSurfaceView(context); > view.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR | > GLSurfaceView.DEBUG_LOG_GL_CALLS); > view.setEGLConfigChooser(false); > if ( renderer != null ) { > view.setRenderer(renderer); > view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); > } > view.getHolder().setFormat(PixelFormat.OPAQUE); > return view; > } // make gl surface view > > onDrawFrame -- > > // Everything stuffed into onDrawFrame to make it easy to read on > forum > @Override > public void onDrawFrame(GL10 gl) { > gl.glClearColor(0,0,.2f, 1f); > gl.glDisable(GL10.GL_CULL_FACE); > gl.glShadeModel(GL10.GL_FLAT); > gl.glDisable(GL10.GL_DEPTH_TEST); > gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); > gl.glMatrixMode(GL10.GL_PROJECTION); > gl.glLoadIdentity(); > gl.glViewport(0, 0, MyApp._width, MyApp._height); > gl.glEnable(GL10.GL_BLEND); > gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); > gl.glEnable(GL10.GL_LINE_SMOOTH); > gl.glDisableClientState(GL10.GL_COLOR_ARRAY); > _hgt2width = (float) MyApp._width / MyApp._height; > gl.glOrthof(-_hgt2width, _hgt2width, -1, 1, 1, -1); > > gl.glScalef(1, _hgt2width, 1); > gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); > > float lscale = .002f*MyApp._curScale; > > gl.glPushMatrix(); > gl.glColor4f(1f, 1f, 0f, 1f); > > gl.glTranslatef(.375f, .5f, 0f); > gl.glScalef( lscale, lscale, 1f); > gl.glVertexPointer(2, GL10.GL_FIXED, 0, _lineVertices); > gl.glLin
[android-developers] Re: How to test OpenGL?
Source code is below. Robert Green provides some helpful information, for which I am thankful. However, I am not clear on two of the points. I currently have the situation where no lines at all show on the emulator (the background color does) and things work perfectly on the G1. On Aug 2, 11:26 am, Robert Green wrote: > 1) You are in a native resolution to the screen you're rendering on > (turn all the density and screen-size stuff on in the manifest to > avoid compat mode) Are these the attributes on the "support-screens" tag? I did not have that tag, but adding it and turning on all the attributes in the check- boxes did not solve the problem. > 2) You draw the lines centered on their pixel, so they look a half > pixel off. > -- To draw a horizontal line across the top row of pixels, you need to > make the line with 1.0f and have y be 0.5f (because it will draw from > 0 to 1 that way) I am drawing in fixed point projection(?) space, so the relationship of the lines to pixels is not clear. Also, I don't want to have to redraw the lines when the scale changes - I want to be able to zoom and pan easily. Is there a way to achieve that and have the lines show? > 3) Make sure you don't have any z-fighting. Drawing 2 things on the > exact same plane with depth-test turned on causes bad results on many > opengl implementations. Depth test turned off. I'm doing 2D only, so I think I'm clear there. Again, thanks for the help. CODE SNIPS == - Create glSurfaceView --- private GLSurfaceView makeGLSurfaceView(GLSurfaceView.Renderer renderer, Context context) { GLSurfaceView view = new GLSurfaceView(context); view.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR | GLSurfaceView.DEBUG_LOG_GL_CALLS); view.setEGLConfigChooser(false); if ( renderer != null ) { view.setRenderer(renderer); view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); } view.getHolder().setFormat(PixelFormat.OPAQUE); return view; } // make gl surface view onDrawFrame -- // Everything stuffed into onDrawFrame to make it easy to read on forum @Override public void onDrawFrame(GL10 gl) { gl.glClearColor(0,0,.2f, 1f); gl.glDisable(GL10.GL_CULL_FACE); gl.glShadeModel(GL10.GL_FLAT); gl.glDisable(GL10.GL_DEPTH_TEST); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); gl.glViewport(0, 0, MyApp._width, MyApp._height); gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL10.GL_LINE_SMOOTH); gl.glDisableClientState(GL10.GL_COLOR_ARRAY); _hgt2width = (float) MyApp._width / MyApp._height; gl.glOrthof(-_hgt2width, _hgt2width, -1, 1, 1, -1); gl.glScalef(1, _hgt2width, 1); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); float lscale = .002f*MyApp._curScale; gl.glPushMatrix(); gl.glColor4f(1f, 1f, 0f, 1f); gl.glTranslatef(.375f, .5f, 0f); gl.glScalef( lscale, lscale, 1f); gl.glVertexPointer(2, GL10.GL_FIXED, 0, _lineVertices); gl.glLineWidthx(0x1); drawArrays(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glColor4f(1f, 1f, 1f, 1.0f); gl.glScalef( lscale*8, lscale*8, 1f); gl.glVertexPointer(2, GL10.GL_FIXED, 0, _lineVertices); gl.glLineWidthx(0x1); drawArrays(gl); gl.glPopMatrix(); } void drawArrays(GL10 gl) { gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, 5); //small square gl.glDrawArrays(GL10.GL_LINE_STRIP, 5, 5); //medium square gl.glDrawArrays(GL10.GL_LINE_STRIP, 10, 5);//large square gl.glDrawArrays(GL10.GL_LINE_STRIP, 15, 2);//x axis gl.glDrawArrays(GL10.GL_LINE_STRIP, 17, 2);//y axis gl.glDrawArrays(GL10.GL_LINE_STRIP, 19, 2);//X half gl.glDrawArrays(GL10.GL_LINE_STRIP, 21, 2);//X half } void makeLines() { int hlf = 0x08000; int one = 0x1+hlf; int sml = one/8; int ten = one; int big = 0x4000; Log.d("===jrm", String.format("one:%x big:%x", one, big)); int vertices[] = { -sml , sml,//0 start square - scale 1/10 sml , sml,//1 sml ,-sml,//2 -sml ,-sml,//3 -sml , sml,//4 -one , one,//5 start square - scale 1 one , one,//6 one ,-one,//7 -one ,-one,//8 -one , one,//9 -ten , ten,//10 start square - scale 10 ten , ten,//11 ten ,-ten,//12 -ten ,-ten,//13 -ten , ten,//14 -big , 0,//15 start coord axes over huge area big , 0,//16 0 , big,//17 0 ,-big,//18 -big ,
[android-developers] Re: How to test OpenGL?
Robert Green's reply gives some specific points I couldn't because I'm not really an OpenGL person myself, and definitely illustrates how rendering can vary. But while I certainly would NOT expect identical results from different rendering engines, it does sound to me like the differences you note go beyond what I'd expect from my somewhat limited experience, and the extremely large coordinates does strike me as a point of suspicion. On Aug 2, 10:14 am, SChaser wrote: > It is entirely possible that I am doing something confused (not being > that much of an OGL person), but even then, I would expect to see the > same results on the emulator and the G1. In answer to another > question, the demos work fine on the emulator. > > Is it possible that disappearing lines are caused by the emulator > pixels not matching exactly the Windows pixels to which they are > ultimately rendered? > > The varying width lines didn't appear until I used extremely large > (but within the FP range) coordinates on a few lines. > > I'll post the code when I get home and have access to it. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to test OpenGL?
The emulator uses a software renderer called PixelFlinger. The G1 uses the MSM7200 chip as a hardware renderer. You may get slightly different results. If you are trying to draw lines that are only 1 pixel wide, ensure the following: 1) You are in a native resolution to the screen you're rendering on (turn all the density and screen-size stuff on in the manifest to avoid compat mode) 2) You draw the lines centered on their pixel, so they look a half pixel off. -- To draw a horizontal line across the top row of pixels, you need to make the line with 1.0f and have y be 0.5f (because it will draw from 0 to 1 that way) 3) Make sure you don't have any z-fighting. Drawing 2 things on the exact same plane with depth-test turned on causes bad results on many opengl implementations. On Aug 2, 12:14 pm, SChaser wrote: > It is entirely possible that I am doing something confused (not being > that much of an OGL person), but even then, I would expect to see the > same results on the emulator and the G1. In answer to another > question, the demos work fine on the emulator. > > Is it possible that disappearing lines are caused by the emulator > pixels not matching exactly the Windows pixels to which they are > ultimately rendered? > > The varying width lines didn't appear until I used extremely large > (but within the FP range) coordinates on a few lines. > > I'll post the code when I get home and have access to it. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to test OpenGL?
It is entirely possible that I am doing something confused (not being that much of an OGL person), but even then, I would expect to see the same results on the emulator and the G1. In answer to another question, the demos work fine on the emulator. Is it possible that disappearing lines are caused by the emulator pixels not matching exactly the Windows pixels to which they are ultimately rendered? The varying width lines didn't appear until I used extremely large (but within the FP range) coordinates on a few lines. I'll post the code when I get home and have access to it. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to test OpenGL?
My thought was, "why don't you show us exactly HOW you draw these lines?" I do take note of your point about some of the lines having endpoints near the edge of the range. Edge cases are more likely to demonstrate bugs. So assuming you aren't doing something confused, you may have some good test cases to offer -- but you'd need to actually offer the reproducible test case, and not just a description of the symptoms. And you'll get a lot more useful responses. On Aug 1, 11:47 pm, Indicator Veritatis wrote: > I have run several OpenGL programs on both emulator and G1, yet I have > never seen any of the effects you mention. > > I cannot explain why you see them and I do not. I can think to ask: do > you see them when you run the OpenGL programs in APIDemo? > > On Aug 1, 7:31 pm, SChaser wrote: > > > > > After a frustrating day of having the Emulator render lines strangely, > > and then discovering that my G1 renders them exactly as I expect, I am > > left to wonder how to test OpenGL (using GLSurfaceView). > > > Is the emulator sufficient to test code for correctness? I ask because > > I experienced the following on the emulator, but not on the G1, all > > using Ortho projection. > > > 1) Line width depending on length! I drew a series of lines, most > > fairly short but several with endpoints close to the edge of the fixed- > > point number range. The long lines were rendered as wide. The short > > lines were rendered as 1 pixel wide. > > > 2) Lines exploding to fill the whole screen when not appropriate to > > the scale (double the scale, line goes from 1/10th screen width to > > filling screen (or more). > > > 3) Lines not appearing at all if horizontal. > > > Is the emulator a correct openGL implementation? If I see problems on > > the emulator, am I likely to see them on some hardware platforms? > > > Can I use my G1 as a reference platform? > > > Or do I need a whole slew of phones to verify that an openGl app > > (scientific graphics, not animated) works across all platforms? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to test OpenGL?
I have run several OpenGL programs on both emulator and G1, yet I have never seen any of the effects you mention. I cannot explain why you see them and I do not. I can think to ask: do you see them when you run the OpenGL programs in APIDemo? On Aug 1, 7:31 pm, SChaser wrote: > After a frustrating day of having the Emulator render lines strangely, > and then discovering that my G1 renders them exactly as I expect, I am > left to wonder how to test OpenGL (using GLSurfaceView). > > Is the emulator sufficient to test code for correctness? I ask because > I experienced the following on the emulator, but not on the G1, all > using Ortho projection. > > 1) Line width depending on length! I drew a series of lines, most > fairly short but several with endpoints close to the edge of the fixed- > point number range. The long lines were rendered as wide. The short > lines were rendered as 1 pixel wide. > > 2) Lines exploding to fill the whole screen when not appropriate to > the scale (double the scale, line goes from 1/10th screen width to > filling screen (or more). > > 3) Lines not appearing at all if horizontal. > > Is the emulator a correct openGL implementation? If I see problems on > the emulator, am I likely to see them on some hardware platforms? > > Can I use my G1 as a reference platform? > > Or do I need a whole slew of phones to verify that an openGl app > (scientific graphics, not animated) works across all platforms? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en