Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6830039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:34:15+00:00 2026-05-26T22:34:15+00:00

I’m making a simple fractal viewing app for Android, just for fun. I’m also

  • 0

I’m making a simple fractal viewing app for Android, just for fun. I’m also using it as an oppotunity to learn OpenGL since I’ve never worked with it before. Using the Android port of the NeHe tutorials as a starting point, my approach is to have one class (FractalModel) which does all the math to create the fractal, and FractalView which does all the rendering.

The difficulty I’m having is in getting the rendering to work. Since I’m essentially plotting a graph of points of different colors where each point should correspond to 1 pixel, I thought I’d handle this by rendering 1×1 rectangles over the entire screen, using the dimensions to calculate the offsets so that there’s a 1:1 correspondence between the rectangles and the physical pixels. Since the color of each pixel will be calculated independently, I can re-use the same rendering code to render different parts of the fractal (I want to add panning and zooming later on).

Here is the view class I wrote:

public class FractalView extends GLSurfaceView implements Renderer {

private float[] mVertices;
private FloatBuffer[][] mVBuffer;
private ByteBuffer[][] mBuffer;
private int mScreenWidth;
private int mScreenHeight;
private float mXOffset;
private float mYOffset;
private int mNumPixels;

//references to current vertex coordinates
private float xTL;
private float yTL;
private float xBL;
private float yBL;
private float xBR;
private float yBR;
private float xTR;
private float yTR;


public FractalView(Context context, int w, int h){
    super(context);
    setEGLContextClientVersion(1);
    mScreenWidth = w;
    mScreenHeight = h;
    mNumPixels = mScreenWidth * mScreenHeight;
    mXOffset = (float)1.0/mScreenWidth;
    mYOffset = (float)1.0/mScreenHeight;
    mVertices = new float[12];
    mVBuffer = new FloatBuffer[mScreenHeight][mScreenWidth];
    mBuffer = new ByteBuffer[mScreenHeight][mScreenWidth];
}


public void onDrawFrame(GL10 gl){
    int i,j;    
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);    
    gl.glLoadIdentity();
    mapVertices();  
    gl.glColor4f(0.0f,1.0f, 0.0f,.5f);
    for(i = 0; i < mScreenHeight; i++){
        for(j = 0; j < mScreenWidth; j++){
            gl.glFrontFace(GL10.GL_CW);
            gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVBuffer[i][j]);
            gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, mVertices.length / 3);
            gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        }
    }




}

public void onSurfaceChanged(GL10 gl, int w, int h){
    if(h == 0) {                        //Prevent A Divide By Zero By
        h = 1;                      //Making Height Equal One
    }

    gl.glViewport(0, 0, w, h);  //Reset The Current Viewport
    gl.glMatrixMode(GL10.GL_PROJECTION);    //Select The Projection Matrix
    gl.glLoadIdentity();                    //Reset The Projection Matrix

    //Calculate The Aspect Ratio Of The Window
    GLU.gluPerspective(gl, 45.0f, (float)w / (float)h, 0.1f, 100.0f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);     //Select The Modelview Matrix
    gl.glLoadIdentity();

}

public void onSurfaceCreated(GL10 gl, EGLConfig config){
    gl.glShadeModel(GL10.GL_SMOOTH);            //Enable Smooth Shading
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    //Black Background
    gl.glClearDepthf(1.0f);                     //Depth Buffer Setup
    gl.glEnable(GL10.GL_DEPTH_TEST);            //Enables Depth Testing
    gl.glDepthFunc(GL10.GL_LEQUAL);             //The Type Of Depth Testing To Do

    //Really Nice Perspective Calculations
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); 
}

private void mapVertices(){
    int i,j;
    xTL = -1;
    yTL = 1;
    xTR = -1 + mXOffset;
    yTR = 1;
    xBL = -1;
    yBL = 1 - mYOffset;
    xBR = -1 + mXOffset;
    yBR = 1 - mYOffset;
    for(i = 0; i < mScreenHeight; i++){
        for (j = 0; j < mScreenWidth; j++){
            //assign coords to vertex array         
            mVertices[0] = xBL;
            mVertices[1] = yBL;
            mVertices[2] = 0f;
            mVertices[3] = xBR;
            mVertices[4] = xBR;
            mVertices[5] = 0f;
            mVertices[6] = xTL;
            mVertices[7] = yTL;
            mVertices[8] = 0f;
            mVertices[9] = xTR;
            mVertices[10] = yTR;
            mVertices[11] = 0f;
            //add doubleBuffer
            mBuffer[i][j] = ByteBuffer.allocateDirect(mVertices.length * 4);
            mBuffer[i][j].order(ByteOrder.nativeOrder());
            mVBuffer[i][j] = mBuffer[i][j].asFloatBuffer();
            mVBuffer[i][j].put(mVertices);
            mVBuffer[i][j].position(0);
            //transform right
            transformRight();
        }
        //transform down
        transformDown();
        //reset x
        xTL = -1;
        xTR = -1 + mXOffset;
        xBL = -1;
        xBR = -1 + mXOffset;
    }



}

//transform all the coordinates 1 "pixel" to the right
private void transformRight(){
    xTL = xTL + mXOffset; //TL            
    xBL = xBL + mXOffset; //BL
    xBR = xBR + mXOffset; //BR
    xTR = xTR + mXOffset; //TR;
}

//transform all of the coordinates 1 pixel down;
private void transformDown(){
    yTL = yTL - mYOffset;                        
    yBL = yBL - mYOffset;            
    yBR = yBR - mYOffset;           
    yTR = yTR - mYOffset;
}
}

Basically I’m trying to do it the same way as this (the square in lesson 2) but with far more objects. I’m assuming 1 and -1 roughly correspond to screen edges, (I know this isn’t totally true, but I don’t really understand how to use projection matrices and want to keep this as simple as possible unless there’s a good resource out there I can learn from) but I understand that OpenGL’s coordinates are separate from real screen coordinates. When I run my code I just get a black screen (it should be green) but LogCat shows the garbage collector working away so I know something is happening. I’m not sure if it’s just a bug caused by my just not doing something right, or if it’s just REALLY slow. In either case, what should I do differently? I feel like I may be going about this all wrong. I’ve looked around and most of the tutorials and examples are based on the link above.

Edit: I know I could go about this by generating a texture that fills up the entire screen and just drawing that, though the link I read which mentioned it said it would be slower since you’re not supposed to redraw a texture every frame. That said, I only really need to redraw the texture when the perspective changes, so I could write my code to take this into account. The main difficulty I’m having currently is drawing the bitmap, and getting it to display correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:34:16+00:00Added an answer on May 26, 2026 at 10:34 pm

    I would imagine that the blank screen is due to the fact that you are swapping buffers so many times, and also the fact that you are generating all your vertex buffers every frame. Thousands of buffer swaps AND thousands of buffer creations in a single frame would be INCREDIBLY slow.

    One thing to mention is that Android devices have limited memory, so the garbage collector working away is probably an indication that your buffer creation code is eating up a lot of the available memory and the device is trying to free up some for the creation of new buffers.

    I would suggest creating a texture that you fill with your pixel data each frame and then render to a single square that fills the screen. This will increase your speed by a huge amount, and also make your program more flexible.

    Edit:
    Look at the tutorial here : http://www.nullterminator.net/gltexture.html to get an idea on how to create textures and load them. You will basically need to fill BYTE* data with your own data.

    If you are changing the data dynamically, you will need to update the texture data. Use the information here : http://www.opengl.org/wiki/Texture : in the section about Texture image modification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.