• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
sjk

2 Display Lists slower?

6 posts in this topic

Hi I'm making my first steps in game programming and tried to use display lists for the first time. I hope my code makes at least some sence at all. ;)

For practice I'm making a 2D Jump n Run with a randomly generated world. My problem is that if I use more than one display list my fps start to drop. But with one list they improve. I'm using Java with lwjgl.


The world is saved into a 2D array:

[code] public static void generate() {

//generate random world
for (int col = 0; col < cols; col++) {
for (int row = 12; row < rows; row++) {
a[col][row]= (int) (Math.random()*3);
}
}

//print world array to console
for (int i =0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
System.out.print(" " + a[j][i]);
}
System.out.println("");
}
}


public static void init() {
// print world
for (int col = 0; col < cols; col++) {
for (int row = 6; row < rows; row++) {
if(a[col][row]== 0) Blocks.loadSky(col,row); //why load sky?
if(a[col][row]== 1) Blocks.loadDirt(col,row);
if(a[col][row]== 2) Blocks.loadRock(col,row);
}
}
}[/code]

"generate()" generates the world at start and "init()" runs in my game loop and draws the world.

I commented out my first approach without display lists. I had around 1400 fps at that time.
Then I created only the dirt display list and my fps jumped up to 2700. (when the fps were 2700 the rocks were also rendering just without the list)
But after I implemented my rock display list the fps dropped to 1500.

[code] static int scale = 32;
static int dirt;
static int rock;


//compile() compiles all block types which are later called by loadDirt etc...
public static void compile() {


//number of lists:
dirt = glGenLists(2);

//dirt block
glNewList(dirt, GL_COMPILE);
textureLoader.dirt.bind();
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(-16,-16);
glTexCoord2f(1.0f,0);
glVertex2f(-16,16);
glTexCoord2f(1.0f,1.0f);
glVertex2f(16,16);
glTexCoord2f(0,1.0f);
glVertex2f(16,-16);
glEnd();
glEndList();


rock = dirt+1;

glNewList(rock, GL_COMPILE);
textureLoader.rock.bind();
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(-16,-16);
glTexCoord2f(1.0f,0);
glVertex2f(-16,16);
glTexCoord2f(1.0f,1.0f);
glVertex2f(16,16);
glTexCoord2f(0,1.0f);
glVertex2f(16,-16);
glEnd();
glEndList();
}


public static void loadDirt(int col, int row) {
/*
textureLoader.dirt.bind();
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(scale * col - scale/2,scale * row - scale/2);
glTexCoord2f(1.0f,0);
glVertex2f(scale * col - scale/2,scale * row + scale/2);
glTexCoord2f(1.0f,1.0f);
glVertex2f(scale * col + scale/2,scale * row + scale/2);
glTexCoord2f(0,1.0f);
glVertex2f(scale * col + scale/2,scale * row - scale/2);
glEnd();*/


//store current Matrix
glPushMatrix();

//col and row change all the time => find save format to save the world
//System.out.println(col);

//move block in position
glTranslatef((scale*col),(scale*row),0);

//call dirt list
glCallList(dirt);

//restore old Matrix
glPopMatrix();

}

public static void loadRock(int col, int row) {
/*
textureLoader.rock.bind();
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(scale * col - scale/2,scale * row - scale/2);
glTexCoord2f(1.0f,0);
glVertex2f(scale * col - scale/2,scale * row + scale/2);
glTexCoord2f(1.0f,1.0f);
glVertex2f(scale * col + scale/2,scale * row + scale/2);
glTexCoord2f(0,1.0f);
glVertex2f(scale * col + scale/2,scale * row - scale/2);
glEnd();*/


glPushMatrix();
glTranslatef((scale*col),(scale*row),0);
glCallList(rock);
glPopMatrix();
}

public static void loadSky(int col, int row) {

}[/code]


What I don't understand is, why is the game running faster with one list which creates only the dirt but is almost as slow as before if I use almost the same one for the rock?
Let me know if you need any more information and I hope that makes sense at all.
Thanks!



And how can I post my code an keep its format? Would probably be better to read. Edited by sjk
0

Share this post


Link to post
Share on other sites
[quote name='sjk' timestamp='1338955146' post='4946641']
And how can I post my code an keep its format? Would probably be better to read.
[/quote]
If your code uses the tab character for indentation, it will get lost when you post it on GameDev.net. What I have to do is copy my code into Notepad++, then search and replace all tabs with 4 spaces. Then copy and paste that into GameDev.

As for your question, I have another question. I'll admit it doesn't answer your question. Why are you using the old, deprecated way of rendering in OpenGL instead of using the modern way (through using shaders and the like)?
2

Share this post


Link to post
Share on other sites
Ha! Thank you so much that code looks much better now!

As for why I'm using no shaders, I'm just starting out and haven't come that far yet. If you could point me in the right direction I would appreciate. it ;)
0

Share this post


Link to post
Share on other sites
[quote name='sjk' timestamp='1338956070' post='4946645']
Ha! Thank you so much that code looks much better now!
[/quote]
Yes it does :)

[quote name='sjk' timestamp='1338956070' post='4946645']
As for why I'm using no shaders, I'm just starting out and haven't come that far yet. If you could point me in the right direction I would appreciate. it ;)
[/quote]
To be honest, I'm not sure of any particularly good online resources to learn about shaders. I remember I always wanted to, but it wasn't until I took a computer graphics course at my university and could actually have things properly explained to me in detail and ask questions that I really started to understand it. For what it's worth, my instructor posted all the class slides and recordings of the lectures [url="http://www.eng.utah.edu/~cs5600/schedule.html"]online at the class page[/url]. If I were you, I'd watch the lecture videos, starting at Lecture 15, Hardware Acceleration. The instructor programmed in C, and he uses some matrix code he wrote earlier in the class sometimes, but it should hopefully be fairly straight forward to translate it into Java. I've never used OpenGL in Java though so I'm afraid I'm no help with lwjgl.

[edit]

But if diving into shaders is detrimental to your motivation, just stick with rendering in immediate mode as you are (in which case I'm no help with your display list problem). Edited by Cornstalks
2

Share this post


Link to post
Share on other sites
Your link to the recordings of the lectures looks really interesting I'll definitely save that. I also want to get into shaders but already figured it would be good to learn the fundamentals first.

Like finding out what my display lists are up to. :) Edited by sjk
0

Share this post


Link to post
Share on other sites
[quote name='sjk' timestamp='1338958599' post='4946650']
Your link to the recordings of the lectures looks really interesting I'll definitely save that. I also want to get into shaders but already figured it would be good to learn the fundamentals first.

Like finding out what my display lists are up to. :)
[/quote]

That is a problem with the legacy way of OpenGL. Much of what you learn is no longer valid, and your program is going to be very hard to update or reuse to the new ways. I usually recommend the following tutorial: [url="http://www.arcsynthesis.org/gltut/"]http://www.arcsynthesis.org/gltut/[/url]. It is the best I have seen so far, and it also teach you the basics of 3D programming.
2

Share this post


Link to post
Share on other sites
Wow thanks! That's a pretty nice tutorial. I guess I have a lot of reading to do. :)

If anyone knows something about the display lists I would still appreciate it!
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0