SlideShare a Scribd company logo
1 of 6
Grafika Komputer - Primitive &Transformations 
Membuat Objek Kotak Bergaris dengan menggunakan Eclips 
package com.example.Rectangle; 
import java.nio.ByteBuffer; 
import java.nio.ByteOrder; 
import java.nio.FloatBuffer; 
import javax.microedition.khronos.opengles.GL10; 
public class Rectangle { 
private float vertices[] = { 
-0.7f, -0.5f, 0.0f, // V1 - first vertex 
(x,y,z) 
-0.7f, 0.5f, 0.0f, // V1 - first vertex (x,y,z) 
0.7f, 0.5f, 0.0f, // V1 - first vertex (x,y,z) 
0.7f, -0.5f, 0.0f, // V2 - second vertex 
-0.7f, -0.5f, 0.0f // V1 - first vertex (x,y,z) 
}; 
private float vertices_color[] = { 
1.0f, 1.0f, 1.0f, 1.0f, // V1 - first vertex 
(x,y,z) 
1.0f, 1.0f, 1.0f, 1.0f, // V1 - first vertex 
(x,y,z) 
1.0f, 1.0f, 1.0f, 1.0f, // V1 - first vertex 
(x,y,z) 
1.0f, 1.0f, 1.0f, 1.0f, // V2 - second vertex 
1.0f, 1.0f, 1.0f, 1.0f // V1 - first vertex 
(x,y,z) 
}; 
public static FloatBuffer makeFloatBuffer(float[] arr){ 
ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4); 
bb.order(ByteOrder.nativeOrder()); 
FloatBuffer fb = bb.asFloatBuffer(); 
fb.put(arr); 
fb.position(0); 
return fb; 
} 
public void draw_kotak(GL10 gl) { 
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
gl.glEnableClientState(GL10.GL_COLOR_ARRAY); 
// Point to our vertex buffer 
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, 
makeFloatBuffer(vertices)); 
// Draw the vertices as square 
gl.glColorPointer(4, GL10.GL_FLOAT, 0, 
makeFloatBuffer(vertices_color)); 
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
gl.glColorPointer(4, GL10.GL_FLOAT, 0, 
makeFloatBuffer(vertices_color)); 
gl.glDrawArrays(GL10.GL_TRIANGLES, 2, 3); 
//Disable the client state before leaving 
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); 
gl.glDisableClientState(GL10.GL_COLOR_ARRAY); 
} 
public void draw_line(GL10 gl) { 
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
//gl.glEnableClientState(GL10.GL_COLOR_ARRAY); 
// set the colour for the line (pemberian warna untuk garis) 
gl.glColor4f(0.0f, 0.0f, 0.0f, 1.0f); 
// Point to our vertex buffer (mendata nilai lokasi/posisi titik yang 
menyusun garis) 
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] { 
0.0f, 1.0f, 0.0f, // V1 - first vertex (x,y,z) 
0.0f, 0.0f, 0.0f, // V2 - second vertex 
})); 
// Draw the vertices as lines (menggambar garis dari titik-titik) 
gl.glDrawArrays(GL10.GL_LINES, 0, 2); 
//Disable the client state before leaving 
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); 
//gl.glDisableClientState(GL10.GL_COLOR_ARRAY); 
} 
} 
GIRenderer.java 
package com.example.Rectangle; 
import javax.microedition.khronos.opengles.GL10; 
import javax.microedition.khronos.egl.EGLConfig; 
import com.example.Rectangle.Rectangle; 
import android.opengl.GLU; 
import android.opengl.GLSurfaceView.Renderer; 
public class GlRenderer implements Renderer { 
private Rectangle object; // the triangle to be drawn 
/** Constructor to set the handed over context */ 
public GlRenderer() { 
this.object = new Rectangle(); 
} 
@Override 
public void onDrawFrame(GL10 gl) { 
// clear Screen and Depth Buffer
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | 
GL10.GL_DEPTH_BUFFER_BIT); 
gl.glLoadIdentity(); 
// menampilkan persegi dengan gradasi warna 
gl.glPushMatrix(); 
gl.glTranslatef(0.0f, 0.0f, -5.0f); 
object.draw_kotak(gl); 
gl.glPopMatrix(); 
//menampilkan arsiran garis 
gl.glPushMatrix(); 
gl.glTranslatef(0.0f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
//geser kanan 
gl.glPushMatrix(); 
gl.glTranslatef(0.1f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
gl.glPushMatrix(); 
gl.glTranslatef(0.2f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
gl.glPushMatrix(); 
gl.glTranslatef(0.3f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
gl.glPushMatrix(); 
gl.glTranslatef(0.4f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
gl.glPushMatrix(); 
gl.glTranslatef(0.5f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
gl.glPushMatrix(); 
gl.glTranslatef(0.6f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
//geser kiri 
gl.glPushMatrix(); 
gl.glTranslatef(-0.1f, -0.5f, -5.0f);
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
gl.glPushMatrix(); 
gl.glTranslatef(-0.2f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
gl.glPushMatrix(); 
gl.glTranslatef(-0.3f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
gl.glPushMatrix(); 
gl.glTranslatef(-0.4f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
gl.glPushMatrix(); 
gl.glTranslatef(-0.5f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
gl.glPushMatrix(); 
gl.glTranslatef(-0.6f, -0.5f, -5.0f); 
gl.glLineWidth(1.0f); 
gl.glEnable(GL10.GL_LINE_SMOOTH); 
object.draw_line(gl); 
gl.glPopMatrix(); 
} 
@Override 
public void onSurfaceChanged(GL10 gl, int width, int height) { 
if(height == 0) { //Prevent 
A Divide By Zero By 
height = 1; //Making 
Height Equal One 
} 
gl.glViewport(0, 0, width, height); //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)width / (float)height, 
0.1f, 100.0f); 
gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview 
Matrix 
gl.glLoadIdentity(); //Reset 
The Modelview Matrix
} 
@Override 
public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
object = new Rectangle(); 
} 
} 
MainActivity.java 
package com.example.Rectangle; 
import com.example.Rectangle.GlRenderer; 
import android.opengl.GLSurfaceView; 
import android.os.Bundle; 
import android.app.Activity; 
import android.view.Window; 
import android.view.WindowManager; 
public class MainActivity extends Activity { 
private GLSurfaceView glSurfaceView; 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
// requesting to turn the title OFF 
requestWindowFeature(Window.FEATURE_NO_TITLE); 
// making it full screen 
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
WindowManager.LayoutParams.FLAG_FULLSCREEN); 
// Initiate the Open GL view and 
// create an instance with this activity 
glSurfaceView = new GLSurfaceView(this); 
// set our renderer to be the main renderer with 
// the current activity context 
glSurfaceView.setRenderer(new GlRenderer()); 
setContentView(glSurfaceView); 
} 
/** 
* Remember to resume the glSurface 
*/ 
@Override 
protected void onResume() { 
super.onResume(); 
glSurfaceView.onResume(); 
} 
/**
* Also pause the glSurface 
*/ 
@Override 
protected void onPause() { 
super.onPause(); 
glSurfaceView.onPause(); 
} 
} 
Hasil Screenshoot :

More Related Content

Recently uploaded

The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxheathfieldcps1
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryEugene Lysak
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptxmansk2
 
The Ultimate Guide to Social Media Marketing in 2024.pdf
The Ultimate Guide to Social Media Marketing in 2024.pdfThe Ultimate Guide to Social Media Marketing in 2024.pdf
The Ultimate Guide to Social Media Marketing in 2024.pdfdm4ashexcelr
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTechSoup
 
Essential Safety precautions during monsoon season
Essential Safety precautions during monsoon seasonEssential Safety precautions during monsoon season
Essential Safety precautions during monsoon seasonMayur Khatri
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Denish Jangid
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resourcesaileywriter
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17Celine George
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024CapitolTechU
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesashishpaul799
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxCapitolTechU
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointELaRue0
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...Nguyen Thanh Tu Collection
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxjmorse8
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesRased Khan
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Celine George
 
Behavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdfBehavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdfaedhbteg
 

Recently uploaded (20)

The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
The Ultimate Guide to Social Media Marketing in 2024.pdf
The Ultimate Guide to Social Media Marketing in 2024.pdfThe Ultimate Guide to Social Media Marketing in 2024.pdf
The Ultimate Guide to Social Media Marketing in 2024.pdf
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
Essential Safety precautions during monsoon season
Essential Safety precautions during monsoon seasonEssential Safety precautions during monsoon season
Essential Safety precautions during monsoon season
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
Behavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdfBehavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdf
 

Featured

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Featured (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Grafika komputer - Membuat Objek Kotak Bergaris dengan Java Eclipse

  • 1. Grafika Komputer - Primitive &Transformations Membuat Objek Kotak Bergaris dengan menggunakan Eclips package com.example.Rectangle; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import javax.microedition.khronos.opengles.GL10; public class Rectangle { private float vertices[] = { -0.7f, -0.5f, 0.0f, // V1 - first vertex (x,y,z) -0.7f, 0.5f, 0.0f, // V1 - first vertex (x,y,z) 0.7f, 0.5f, 0.0f, // V1 - first vertex (x,y,z) 0.7f, -0.5f, 0.0f, // V2 - second vertex -0.7f, -0.5f, 0.0f // V1 - first vertex (x,y,z) }; private float vertices_color[] = { 1.0f, 1.0f, 1.0f, 1.0f, // V1 - first vertex (x,y,z) 1.0f, 1.0f, 1.0f, 1.0f, // V1 - first vertex (x,y,z) 1.0f, 1.0f, 1.0f, 1.0f, // V1 - first vertex (x,y,z) 1.0f, 1.0f, 1.0f, 1.0f, // V2 - second vertex 1.0f, 1.0f, 1.0f, 1.0f // V1 - first vertex (x,y,z) }; public static FloatBuffer makeFloatBuffer(float[] arr){ ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(arr); fb.position(0); return fb; } public void draw_kotak(GL10 gl) { gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_COLOR_ARRAY); // Point to our vertex buffer gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices)); // Draw the vertices as square gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_color)); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
  • 2. gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_color)); gl.glDrawArrays(GL10.GL_TRIANGLES, 2, 3); //Disable the client state before leaving gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_COLOR_ARRAY); } public void draw_line(GL10 gl) { gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); //gl.glEnableClientState(GL10.GL_COLOR_ARRAY); // set the colour for the line (pemberian warna untuk garis) gl.glColor4f(0.0f, 0.0f, 0.0f, 1.0f); // Point to our vertex buffer (mendata nilai lokasi/posisi titik yang menyusun garis) gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] { 0.0f, 1.0f, 0.0f, // V1 - first vertex (x,y,z) 0.0f, 0.0f, 0.0f, // V2 - second vertex })); // Draw the vertices as lines (menggambar garis dari titik-titik) gl.glDrawArrays(GL10.GL_LINES, 0, 2); //Disable the client state before leaving gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); //gl.glDisableClientState(GL10.GL_COLOR_ARRAY); } } GIRenderer.java package com.example.Rectangle; import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.egl.EGLConfig; import com.example.Rectangle.Rectangle; import android.opengl.GLU; import android.opengl.GLSurfaceView.Renderer; public class GlRenderer implements Renderer { private Rectangle object; // the triangle to be drawn /** Constructor to set the handed over context */ public GlRenderer() { this.object = new Rectangle(); } @Override public void onDrawFrame(GL10 gl) { // clear Screen and Depth Buffer
  • 3. gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); // menampilkan persegi dengan gradasi warna gl.glPushMatrix(); gl.glTranslatef(0.0f, 0.0f, -5.0f); object.draw_kotak(gl); gl.glPopMatrix(); //menampilkan arsiran garis gl.glPushMatrix(); gl.glTranslatef(0.0f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); //geser kanan gl.glPushMatrix(); gl.glTranslatef(0.1f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(0.2f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(0.3f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(0.4f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(0.5f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(0.6f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); //geser kiri gl.glPushMatrix(); gl.glTranslatef(-0.1f, -0.5f, -5.0f);
  • 4. gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(-0.2f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(-0.3f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(-0.4f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(-0.5f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(-0.6f, -0.5f, -5.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); object.draw_line(gl); gl.glPopMatrix(); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { if(height == 0) { //Prevent A Divide By Zero By height = 1; //Making Height Equal One } gl.glViewport(0, 0, width, height); //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)width / (float)height, 0.1f, 100.0f); gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix gl.glLoadIdentity(); //Reset The Modelview Matrix
  • 5. } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { object = new Rectangle(); } } MainActivity.java package com.example.Rectangle; import com.example.Rectangle.GlRenderer; import android.opengl.GLSurfaceView; import android.os.Bundle; import android.app.Activity; import android.view.Window; import android.view.WindowManager; public class MainActivity extends Activity { private GLSurfaceView glSurfaceView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // requesting to turn the title OFF requestWindowFeature(Window.FEATURE_NO_TITLE); // making it full screen getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Initiate the Open GL view and // create an instance with this activity glSurfaceView = new GLSurfaceView(this); // set our renderer to be the main renderer with // the current activity context glSurfaceView.setRenderer(new GlRenderer()); setContentView(glSurfaceView); } /** * Remember to resume the glSurface */ @Override protected void onResume() { super.onResume(); glSurfaceView.onResume(); } /**
  • 6. * Also pause the glSurface */ @Override protected void onPause() { super.onPause(); glSurfaceView.onPause(); } } Hasil Screenshoot :