Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (549)
Games in Android Showcase (136)
games submitted by our members
Games in WIP (594)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  DrawArrays work fine, yet DrawElements doesn't?  (Read 2831 times)
0 Members and 1 Guest are viewing this topic.
Offline NegativeZero
« Posted 2013-06-19 01:29:51 »

So, this is my first 'problem' thread. So I've been toying with VBOs, and after successfully using modified Riven's VBO tutorial to draw a .OBJ file on the screen with DrawArrays, I decided to move onto DrawElements, then interleaving, etc.

However, when it came time to DrawElements, my OBJ wouldn't render properly. So I comment'd that code out, and put in simple code to draw a triangle. This worked.

DrawElements vs. DrawArrays

This is my draw code:
And my init code:
If you zoom upon the Elements, you'll see a few pixel of white being rendered at the bottom.
Offline nhydock

Junior Devvie

Medals: 4
Projects: 2

« Reply #1 - Posted 2013-06-19 01:46:21 »

Please look over documentation on both OpenGL functions

Your problem most likely stems from the fact that you're not passing a proper indices array when using DrawElements, so it doesn't know the order or the obj's vertices.  glDrawArrays assumes an order depending on the set mode.

I also recommend using GL_TRIANGLE_STRIP instead of GL_TRIANGLES for efficiency.
Offline NegativeZero
« Reply #2 - Posted 2013-06-19 05:23:43 »

So after reading that I realized that I was using element count where I should have used index count.
But unfortunately, it hasn't changed anything.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel

Medals: 362
Projects: 3
Exp: 5 years

I'm the King!

« Reply #3 - Posted 2013-06-19 06:20:13 »

Why in the world are you uploading the VBO every single frame?! The glBufferData function should only be called once in your init code since you're using GL_STATIC_DRAW.

Offline NegativeZero
« Reply #4 - Posted 2013-06-19 10:41:32 »

Oh, thanks!
This is the first time I've really played with VBOs(only really used displaylists, prior), so what I'm doing is all rather new to me.
Offline ra4king

JGO Kernel

Medals: 362
Projects: 3
Exp: 5 years

I'm the King!

« Reply #5 - Posted 2013-06-19 17:13:24 »

Anyway are you sure your OBJ only needs 3 indices and 2 normals? Smiley
The few white pixels is the 1 triangle only being drawn instead of the hundreds it may have.

OBJ files don't have indices in the first place btw. That vBuffer that was returned was the only thing you needed to upload once and then use glDrawArrays since there are no elements to possibly upload (unless you want to generate your own Grin).

Offline NegativeZero
« Reply #6 - Posted 2013-06-19 19:25:45 »

So using Draw Elements has no advantage?
Offline ra4king

JGO Kernel

Medals: 362
Projects: 3
Exp: 5 years

I'm the King!

« Reply #7 - Posted 2013-06-20 00:18:55 »

You only use drawElements when you have elements. You don't have elements with this OBJ model therefore use drawArrays. There is no advantage to one over the other it's just whether you have/want to use indices/elements or not.

Offline Riven
« League of Dukes »

« JGO Overlord »

Medals: 875
Projects: 4
Exp: 16 years

Hand over your head.

« Reply #8 - Posted 2013-06-20 00:39:45 »

with glDrawElements you can take advantange of the vertex cache of the GPU, allowing you to (in the most optimal case) only run the vertex shader once for every unique index.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline ra4king

JGO Kernel

Medals: 362
Projects: 3
Exp: 5 years

I'm the King!

« Reply #9 - Posted 2013-06-20 01:29:37 »

Ah yes there are speed/memory advantages of course, I meant no advantage in terms of usage/complexity. Smiley

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.


Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Olo (11 views)
2015-01-25 21:26:00

Olo (13 views)
2015-01-25 18:44:22

Robo11 (21 views)
2015-01-25 06:14:26

basil_ (26 views)
2015-01-17 22:29:32

wxwsk8er (24 views)
2015-01-16 21:42:21

wxwsk8er (20 views)
2015-01-16 20:44:20

basil_ (25 views)
2015-01-14 09:46:59

basil_ (21 views)
2015-01-14 09:46:52

wxwsk8er (33 views)
2015-01-13 20:42:16

wxwsk8er (34 views)
2015-01-13 03:23:59
2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!