Skip to content

Commit

Permalink
Add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
slaviboy committed Oct 14, 2020
1 parent a0dc326 commit cac52ca
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ class OpenGLHelper : View.OnTouchListener {
900f, 600f, 950f, 700f, 400f, 900f // third triangle coordinates
),
intArrayOf(
Color.RED, // first triangle colors
Color.GREEN, // second triangle colors
Color.YELLOW // third triangle colors
Color.RED, // first triangle color
Color.GREEN, // second triangle color
Color.YELLOW // third triangle color
),
style = STYLE_FILL,
preloadProgram = program,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.slaviboy.openglexamples.R
*/
class OpenGLHelper : View.OnTouchListener {

// matrix used for allying transformations to all OpenGL objects: line, images, triangles..
// gesture detector used for applying transformations to all OpenGL objects: line, images, triangles..
var mainGestureDetector: OpenGLMatrixGestureDetector =
OpenGLMatrixGestureDetector()

Expand Down Expand Up @@ -69,7 +69,19 @@ class OpenGLHelper : View.OnTouchListener {
if (context != null) {
val imageProgram = OpenGLStatic.setTextureProgram()
val textureHandler = OpenGLStatic.loadTexture(context, R.drawable.earth)
image = Image(302f, 303f, 50f, 50f, 100f, 100f, textureHandler, imageProgram, true, true, false, mainGestureDetector)
image = Image(
bitmapWidth = 302f,
bitmapHeight = 303f,
x = 50f,
y = 50f,
width = 100f,
height = 100f,
textureHandle = textureHandler,
preloadProgram = imageProgram,
keepSize = true,
usePositionAsCenter = true,
gestureDetector = mainGestureDetector
)
}
strokeFillShapes()
}
Expand Down Expand Up @@ -187,19 +199,82 @@ class OpenGLHelper : View.OnTouchListener {
}

// create shapes
line = Line(100f, 800f, 300f, 800f, Color.RED, 10f, true, mainGestureDetector, singleColorsProgram)
circle = Circle(700f, 700f, 110f, Color.MAGENTA, 5f, true, mainGestureDetector, singleColorsProgram, style)
ellipse = Ellipse(800f, 280f, 50f, 200f, Color.CYAN, 5f, true, mainGestureDetector, singleColorsProgram, style)
rectangle = Rectangle(300f, 200f, 300f, 150f, Color.BLUE, 5f, true, mainGestureDetector, singleColorsProgram, style)
triangle = Triangle(40f, 550f, 200f, 350f, 310f, 650f, Color.RED, 5f, true, mainGestureDetector, singleColorsProgram, style)
regularPolygon = RegularPolygon(500f, 500f, 100f, 0f, Color.GREEN, 5f, true, mainGestureDetector, singleColorsProgram, style, 6)
line = Line(
x1 = 100f, y1 = 800f,
x2 = 300f, y2 = 800f,
color = Color.BLACK,
strokeWidth = 10f,
gestureDetector = mainGestureDetector,
preloadProgram = singleColorsProgram
)

circle = Circle(
x = 700f,
y = 700f,
radius = 110f,
color = Color.BLACK,
strokeWidth = 5f,
gestureDetector = mainGestureDetector,
preloadProgram = singleColorsProgram,
style = style
)

ellipse = Ellipse(
x = 800f,
y = 280f,
rx = 50f,
ry = 200f,
color = Color.BLACK,
strokeWidth = 5f,
gestureDetector = mainGestureDetector,
preloadProgram = singleColorsProgram,
style = style
)

rectangle = Rectangle(
x = 300f,
y = 200f,
width = 300f,
height = 150f,
color = Color.BLACK,
strokeWidth = 5f,
gestureDetector = mainGestureDetector,
preloadProgram = singleColorsProgram,
style = style
)

triangle = Triangle(
x1 = 40f, y1 = 550f,
x2 = 200f, y2 = 350f,
x3 = 310f,
y3 = 650f,
color = Color.BLACK,
strokeWidth = 5f,
gestureDetector = mainGestureDetector,
preloadProgram = singleColorsProgram,
style = style
)

regularPolygon = RegularPolygon(
x = 500f,
y = 500f,
radius = 100f,
angle = 0f,
numberVertices = 6,
color = Color.BLACK,
strokeWidth = 5f,
gestureDetector = mainGestureDetector,
preloadProgram = singleColorsProgram,
style = style
)

passByCurve = PassByCurve(
floatArrayOf(
10.0f, 1042.0f, 50.0f, 1012.0f, 90.0f, 951.0f, 130.0f, 943.0f, 170.0f, 939.0f, 210.0f, 1099.0f, 250.0f, 1021.0f,
290.0f, 1085.0f, 330.0f, 1032.0f, 370.0f, 912.0f, 410.0f, 983.0f, 450.0f, 927.0f, 490.0f, 1021.0f, 530.0f, 935.0f,
570.0f, 976.0f, 610.0f, 1063.0f, 650.0f, 1055.0f, 690.0f, 1089.0f, 730.0f, 1022.0f, 770.0f, 1052.0f, 810.0f,
950.0f, 850.0f, 920.0f, 890.0f, 925.0f, 930.0f, 1047.0f, 970.0f, 993.0f
), Color.BLUE, 5f, true, mainGestureDetector, singleColorsProgram, false, 1f, 40
), Color.BLACK, 5f, true, mainGestureDetector, singleColorsProgram, false, 1f, 40
)

requestRenderListener.invoke()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ class OpenGLRenderer(val context: Context, var openGLHelper: OpenGLHelper, reque

override fun onDrawFrame(unused: GL10) {

// clear the scene
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)

// set MVPMatrix
Matrix.setLookAtM(viewMatrix, 0, 0f, 0f, -3f, 0f, 0f, 0f, 0f, 1.0f, 0.0f)
Matrix.multiplyMM(MVPMatrix, 0, projectionMatrix, 0, viewMatrix, 0)

Expand All @@ -78,14 +80,16 @@ class OpenGLRenderer(val context: Context, var openGLHelper: OpenGLHelper, reque
*/
override fun onSurfaceChanged(unused: GL10, width: Int, height: Int) {

// if alpha is enabled
if (OpenGLStatic.ENABLE_ALPHA) {
GLES20.glEnable(GLES20.GL_BLEND)
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA)
}

// set device size and ratio
OpenGLStatic.setComponents(width.toFloat(), height.toFloat())

// Adjust the viewport based on geometry changes, such as screen rotation
// adjust the viewport based on geometry changes, such as screen rotation
GLES20.glViewport(0, 0, width, height)

// this projection matrix is applied to object coordinates
Expand All @@ -95,6 +99,7 @@ class OpenGLRenderer(val context: Context, var openGLHelper: OpenGLHelper, reque
openGLHelper.mainGestureDetector.matrix = android.graphics.Matrix()
openGLHelper.mainGestureDetector.matrix.postTranslate(OpenGLStatic.DEVICE_HALF_WIDTH, OpenGLStatic.DEVICE_HALF_HEIGHT)

// create the shapes
openGLHelper.createShapes(context)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ class OpenGLSurfaceView : GLSurfaceView {

init {

// whether to enable alpha
if (ENABLE_ALPHA) {
holder.setFormat(PixelFormat.TRANSLUCENT)
}

// create an OpenGL ES 2.0 context.
// create an OpenGL ES 2.0 context
setEGLContextClientVersion(2)

// fix for error No Config chosen
Expand All @@ -66,5 +67,4 @@ class OpenGLSurfaceView : GLSurfaceView {
// render the view only when there is a change in the drawing data
renderMode = RENDERMODE_WHEN_DIRTY
}

}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.2'
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 22 11:51:30 EEST 2020
#Wed Oct 14 05:51:31 EEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\:https://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\:https://services.gradle.org/distributions/gradle-6.5-bin.zip

0 comments on commit cac52ca

Please sign in to comment.