Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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 2649 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 03: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

Junior Member


Medals: 4
Projects: 2



« Reply #1 - Posted 2013-06-19 03: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 07: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: 340
Projects: 2
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2013-06-19 08: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 12: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: 340
Projects: 2
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2013-06-19 19: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 21:25:45 »

So using Draw Elements has no advantage?
Offline ra4king

JGO Kernel


Medals: 340
Projects: 2
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2013-06-20 02: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.

Online Riven
« League of Dukes »

JGO Overlord


Medals: 746
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2013-06-20 02: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: 340
Projects: 2
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2013-06-20 03: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.

CogWheelz (2 views)
2014-07-30 21:08:39

Riven (20 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (28 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!