public class Square;square.draw(gl); // ( NEW )

10 篇文章 0 订阅
package se.jayway.opengl.tutorial;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import javax.microedition.khronos.opengles.GL10;

public class Square {
	// Our vertices.
	private float vertices[] = {
	-1.0f, 1.0f, 0.0f, // 0, Top Left
	-1.0f, -1.0f, 0.0f, // 1, Bottom Left
	1.0f, -1.0f, 0.0f, // 2, Bottom Right
	1.0f, 1.0f, 0.0f, // 3, Top Right
	};
	// The order we like to connect them.
	private short[] indices = { 0, 1, 2, 0, 2, 3 };
	// Our vertex buffer.
	private FloatBuffer vertexBuffer;
	// Our index buffer.
	private ShortBuffer indexBuffer;
	public Square() {
	// a float is 4 bytes, therefore we multiply the number if
	// vertices with 4.
	ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
	vbb.order(ByteOrder.nativeOrder());
	vertexBuffer = vbb.asFloatBuffer();
	vertexBuffer.put(vertices);
	vertexBuffer.position(0);
	// short is 2 bytes, therefore we multiply the number if
	// vertices with 2.
	ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * 2);
	ibb.order(ByteOrder.nativeOrder());
	indexBuffer = ibb.asShortBuffer();
	indexBuffer.put(indices);
	indexBuffer.position(0);
	}
	/**
	* This function draws our square on screen.
	* @param gl
	*/
	public void draw(GL10 gl) {
	// Counter-clockwise winding.
	gl.glFrontFace(GL10.GL_CCW); // OpenGL docs
	// Enable face culling.
	gl.glEnable(GL10.GL_CULL_FACE); // OpenGL docs
	// What faces to remove with the face culling.
	gl.glCullFace(GL10.GL_BACK); // OpenGL docs
	// Enabled the vertices buffer for writing and to be used during
	// rendering.
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);// OpenGL docs.
	// Specifies the location and data format of an array of vertex
	// coordinates to use when rendering.
	gl.glVertexPointer(3, GL10.GL_FLOAT, 0, // OpenGL docs
	vertexBuffer);
	gl.glDrawElements(GL10.GL_TRIANGLES, indices.length,// OpenGL docs
	GL10.GL_UNSIGNED_SHORT, indexBuffer);
	// Disable the vertices buffer.
	gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); // OpenGL docs
	// Disable face culling.
	gl.glDisable(GL10.GL_CULL_FACE); // OpenGL docs
	}
	
}



package se.jayway.opengl.tutorial;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLU;
import android.opengl.GLSurfaceView.Renderer;

public class OpenGLRenderer implements Renderer {
	/*
	* (non-Javadoc)
	*
	* @see
	* android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(javax.
	* microedition.khronos.opengles.GL10, javax.microedition.khronos.
	* egl.EGLConfig)
	*/
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
	// Set the background color to black ( rgba ).
	gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // OpenGL docs.
	// Enable Smooth Shading, default not really needed.
	gl.glShadeModel(GL10.GL_SMOOTH);// OpenGL docs.
	// Depth buffer setup.
	gl.glClearDepthf(1.0f);// OpenGL docs.
	// Enables depth testing.
	gl.glEnable(GL10.GL_DEPTH_TEST);// OpenGL docs.
	// The type of depth testing to do.
	gl.glDepthFunc(GL10.GL_LEQUAL);// OpenGL docs.
	// Really nice perspective calculations.
	gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, // OpenGL docs.
	GL10.GL_NICEST);
	}
	/*
	* (non-Javadoc)
	*
	* @see
	* android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.
	* microedition.khronos.opengles.GL10)
	*/
	// Initialize our square.
	Square square = new Square();

	public void onDrawFrame(GL10 gl) {
	// Clears the screen and depth buffer.
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | // OpenGL docs.
	GL10.GL_DEPTH_BUFFER_BIT);
	
	// Replace the current matrix with the identity matrix
	gl.glLoadIdentity(); // OpenGL docs
	// Translates 4 units into the screen.
	gl.glTranslatef(0, 0, -4); // OpenGL docs
	// Draw our square.
	square.draw(gl); // ( NEW )
	}
	/*
	* (non-Javadoc)
	*
	* @see
	* android.opengl.GLSurfaceView.Renderer#onSurfaceChanged(javax.
	* microedition.khronos.opengles.GL10, int, int)
	*/
	public void onSurfaceChanged(GL10 gl, int width, int height) {
	// Sets the current view port to the new size.
	gl.glViewport(0, 0, width, height);// OpenGL docs.
	// Select the projection matrix
	gl.glMatrixMode(GL10.GL_PROJECTION);// OpenGL docs.
	// Reset the projection matrix
	gl.glLoadIdentity();// OpenGL docs.
	// Calculate the aspect ratio of the window
	GLU.gluPerspective(gl, 45.0f,
	(float) width / (float) height,
	0.1f, 100.0f);
	// Select the modelview matrix
	gl.glMatrixMode(GL10.GL_MODELVIEW);// OpenGL docs.
	// Reset the modelview matrix
	gl.glLoadIdentity();// OpenGL docs.
	}
	
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以根据注释添加以下内容: - JTextField类型的usernameField属性声明,用于输入用户名。 - JPasswordField类型的passwordField属性声明,用于输入密码。 - JButton类型的loginButton属性声明,用于触发登录操作。 - LoginFrame构造函数,用于初始化登录界面。 - getter和setter方法,用于获取和设置用户名、密码和登录按钮的属性值。 完整代码如下: ``` class LoginFrame extends JFrame { private JTextField usernameField; // 用户名输入框 private JPasswordField passwordField; // 密码输入框 private JButton loginButton; // 登录按钮 public LoginFrame() { // 界面初始化 // ... // 初始化用户名输入框 usernameField = new JTextField(); // 初始化密码输入框 passwordField = new JPasswordField(); // 初始化登录按钮 loginButton = new JButton("登录"); // 将输入框和登录按钮添加到登录界面 // ... // 设置登录按钮的事件监听器 // ... } // getter和setter方法 public String getUsername() { return usernameField.getText(); } public void setUsername(String username) { usernameField.setText(username); } public String getPassword() { return new String(passwordField.getPassword()); } public void setPassword(String password) { passwordField.setText(password); } public void setLoginButtonEnabled(boolean enabled) { loginButton.setEnabled(enabled); } } ``` 这个类定义了一个登录界面,包括用户名输入框、密码输入框和登录按钮,并提供了相应的构造方法和getter/setter方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值