Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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 2745 times)
0 Members and 1 Guest are viewing this topic.
Offline NegativeZero

JGO Knight


Medals: 30
Projects: 2
Exp: 3 years


Zero but not.


« 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: http://pastebin.java-gaming.org/fa705631367
And my init code: http://pastebin.java-gaming.org/a705373176f
If you zoom upon the Elements, you'll see a few pixel of white being rendered at the bottom.
Offline nhydock
« Reply #1 - Posted 2013-06-19 01:46:21 »

Please look over documentation on both OpenGL functions

http://www.opengl.org/sdk/docs/man/xhtml/glDrawArrays.xml
http://www.opengl.org/sdk/docs/man/xhtml/glDrawElements.xml

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.

http://www.opengl.org/discussion_boards/showthread.php/173362-GL_TRIANGLES-vs-GL_TRIANGLE_FAN-STRIP
Offline NegativeZero

JGO Knight


Medals: 30
Projects: 2
Exp: 3 years


Zero but not.


« 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: 350
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

JGO Knight


Medals: 30
Projects: 2
Exp: 3 years


Zero but not.


« 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: 350
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

JGO Knight


Medals: 30
Projects: 2
Exp: 3 years


Zero but not.


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

So using Draw Elements has no advantage?
Offline ra4king

JGO Kernel


Medals: 350
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: 817
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: 350
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.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
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

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!