OpenGL ES-must use a native order direct Buffer Solution

Source: Internet
Author: User

OpenGL ES is similarCode:

1) create three vertices

PrivateIntbuffer triggerbuffer = intbuffer. Wrap (New Int[] {

0, One,0,

-One,-one,0,

One,-one,0,

});

2) use triggerbuffer to draw the vertex

Example: Gl. glvertexpointer (3, gl10.gl _ fixed, 0, triggerbuffer );

Must use a native order direct buffer error often occurs.

 

Solution: (create a method)

/*
* OpenGL is a very underlying drawing interface. Its buffer storage structure is consistent with our Java Program .
* Java uses bigedian, while OpenGL uses littleedian ).
* Therefore, we need to do some work when converting the Java buffer to the buffer zone available for OpenGL. The following describes how to create a buff:
**/
Public buffer bufferutil (INT [] ARR ){
Intbuffer mbuffer;
// Initialize the buffer first. The array length is * 4, because an int occupies 4 bytes.
Bytebuffer qbb = bytebuffer. allocatedirect (ARR. length * 4 );
// Nativeorder is used for Array Arrangement
Qbb. Order (byteorder. nativeorder ());

Mbuffer = qbb. asintbuffer ();
Mbuffer. Put (ARR );
Mbuffer. Position (0 );

Return mbuffer;
}

Next (also two steps ):

1) use an int array to create a vertex

PrivateInt [] triggerbuffer =New Int[] {

0, One,0,

-One,-one,0,

One,-one,0,

};

2) use Arrays

Gl. glvertexpointer (3, gl10.gl _ fixed, 0, bufferutil (triggerbuffer );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.