Wireframe in OpenGL

There are 3 approaches I know about:

1. ) glPolygonMode

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glDrawArrays(GL_TRIANGLES, 0, numOfVertices);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

2.) For OpenGL ES

http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/

3.) Dirty way to draw wireframe

for(ulong i = 0; i < numOfVertices; i += 3)
glDrawArrays(GL_LINE_LOOP, i, 3);

Advertisements

2D HUD graphics over 3D objects in Modern OpenGL

First we need to initialize our VBO(s) (Vertex Buffer Objects) with desired data. I’ll skip the 3D objects’ initialization and rendering in this post.

// Initialize the VBO data
float vert[9], colr[9]; // array variables to hold vertex data

// These values are according to screen size of 1920p width and 1080p height
vert[0] = 960.0f; vert[1] = 540.0f; vert[2] = 1.0f; // TOP
vert[3] = 900.0f; vert[4] = 10.0f; vert[5] = 1.0f; // LEFT
vert[6] = 500.0f; vert[7] = 540.0f; vert[8] = 1.0f; // RIGHT

glGenBuffers(1, &amp;vbo);

glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), vert, GL_STATIC_DRAW);
glVertexAttribPointer(gvPositionHandle, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(gvPositionHandle);

// unbind buffers
glBindBuffer(GL_ARRAY_BUFFER, 0);

colr[0] = 1.0f; colr[1] = 0.0f; colr[2] = 0.0f; // TOP
colr[3] = 0.0f; colr[4] = 1.0f; colr[5] = 0.0f; // LEFT
colr[6] = 0.0f; colr[7] = 0.0f; colr[8] = 1.0f; // RIGHT
// COLOR VBO
glGenBuffers(1, &amp;cvbo);
glBindBuffer(GL_ARRAY_BUFFER, cvbo);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), colr, GL_STATIC_DRAW);
glVertexAttribPointer(gvColorHandle, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(gvColorHandle);
// unbind buffers
glBindBuffer(GL_ARRAY_BUFFER, 0);

Now in your drawing function

void drawOpenGLWorld() {
.
.
.
// Draw all your 3D objects
// Now draw your 2D HUD
// Create an orthograpic matrix for WIDTH and HEIGHT of your screen's drawing area
Ortho = glm::ortho(0.0f, (float)width, (float)height, 0.0f);

glDisable(GL_DEPTH_TEST); // Disable the Depth-testing

glm::mat4 _guiMVP;
_guiMVP = Ortho * glm::mat4(1.0f); // Identity Matrix

glUniformMatrix4fv(MatrixID, 1, GL_FALSE, glm::value_ptr(_guiMVP));

glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(gvPositionHandle, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(gvPositionHandle);

glBindBuffer(GL_ARRAY_BUFFER, cvbo);
glVertexAttribPointer(gvColorHandle, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(gvColorHandle);

glDrawArrays(GL_TRIANGLES, 0, 3); // draw first object
// un-bind the VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);

glEnable(GL_DEPTH_TEST); // Enable the Depth-testing
.
.
.
}

Here’s a screenshot of an OpenGL window with dimensions of 1920×1080 having a triangle placed over 3D objects :

2D graphics over 3D world in OpenGL

You can also add Textures and other cool effects to your 2D HUD. So what are you waiting for; Go ahead .. .experiment on your own !

Register for an IRC channel

Loin to IRC server with a unique NICKNAME then you get a message like this :

#android-dev Cannot join channel (+r) – you need to be identified with services

Run the following command, enter a strong password and your primary email id :

/msg NickServ REGISTER yourircpassword youraddress@email.com

you will get output like this :

*NickServ* REGISTER yourircpassword youraddress@email.com
NickServ- An email containing nickname activation instructions has been sent to youraddress@email.com.
NickServ- If you do not complete registration within one day, your nickname will expire.
NickServ- NICKNAME is now registered to youraddress@email.com, with the password wer.ck!.
NickServ-

NickServ- For frequently-asked questions about the network, please see the NickServ- FAQ page (http://freenode.net/faq.shtml). Should you need more NickServ- help you can /join #freenode to find network staff.

Goto your inbox and you will find instruction like this :
/msg NickServ VERIFY REGISTER NICKNAME SECRETKEY

execute this command to verify your nickname.

To keep your email address private, rather than displaying it publicly, mark it as hidden (which is done by default for new accounts):
/msg NickServ SET HIDEMAIL ON

Join a channel using this command :
/join android-dev

To Mention a user in chat do this :
Type a few characters of his NickName then press TAB Key.

Generate Thumbnails for images on Android

From here I Get this code

byte[] imageData = null;

        try     
        {

            final int THUMBNAIL_SIZE = 64;

            FileInputStream fis = new FileInputStream(fileName);
            Bitmap imageBitmap = BitmapFactory.decodeStream(fis);

            imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();  
            imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            imageData = baos.toByteArray();

        }
        catch(Exception ex) {

        }

There’s another approach if you want better control on Thumbnail dimensions :

public static final int THUMBNAIL_HEIGHT = 48;
public static final int THUMBNAIL_WIDTH = 66;

imageBitmap = BitmapFactory.decodeByteArray(mImageData, 0, mImageData.length);
Float width  = new Float(imageBitmap.getWidth());
Float height = new Float(imageBitmap.getHeight());
Float ratio = width/height;
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, (int)(THUMBNAIL_HEIGHT*ratio), THUMBNAIL_HEIGHT, false);

int padding = (THUMBNAIL_WIDTH - imageBitmap.getWidth())/2;
imageView.setPadding(padding, 0, padding, 0);
imageView.setImageBitmap(imageBitmap);

ByteArrayOutputStream baos = new ByteArrayOutputStream();  
imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] byteArray = baos.toByteArray();

After generating thumbnail, convert it to base64 string like this :

String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);

That’s It.