OpenGL Main Loop [SOLVED]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
g0bl1n
Posts: 63
Joined: Thu Feb 21, 2008 8:45 am

OpenGL Main Loop [SOLVED]

Post by g0bl1n »

Just curious, is there a way to use the OpenGL render function for drawing (Quads, Triangle Fans, etc...)?
Last edited by g0bl1n on Thu Apr 05, 2012 2:43 am, edited 1 time in total.
teto
Posts: 159
Joined: Thu Dec 03, 2009 9:37 pm
Location: /home
Contact:

Re: OpenGL Main Loop

Post by teto »

check irr::video::IVideoDriver::drawVertexPrimitiveList in doc.
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
g0bl1n
Posts: 63
Joined: Thu Feb 21, 2008 8:45 am

Re: OpenGL Main Loop

Post by g0bl1n »

I'm not quite sure what I'm doing wrong, I can't get anything to show up on the screen. I looked at a few other posts and tried a few different examples but I can't get anyone else's code to show up either, am I missing something? Below is my current code (should draw a white cube face without backface culling).

Verts and Prims Declaration:

Code: Select all

float size=100;
float verts[4][3]=
{
        {-size,size,0},
        {size,size,0},
        {size,-size,0},
        {-size,-size,0}
};
 
unsigned int prims[4]=
{
        0,1,2,3
};
Draw Code (in main loop):

Code: Select all

irr::video::SMaterial material;
material.BackfaceCulling=false;
material.EmissiveColor.set(0xffFFff);
device->getVideoDriver()->setMaterial(material);
device->getVideoDriver()->setTransform(irr::video::ETS_WORLD,irr::core::matrix4());
device->getVideoDriver()->drawVertexPrimitiveList(verts,12,prims,4,irr::video::EVT_STANDARD,irr::scene::EPT_QUADS);
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: OpenGL Main Loop

Post by mongoose7 »

Well ... your vertices are not EVT_STANDARD.

I can't see the point in using Irrlicht for rendering but not using the render function. Are you just trying to learn OpenGL?
g0bl1n
Posts: 63
Joined: Thu Feb 21, 2008 8:45 am

Re: OpenGL Main Loop

Post by g0bl1n »

I've found that drawing things yourself can be faster because you can do a whole lot of them at one time. Take Minecraft for example, try drawing 200,000 box nodes vs. drawing all the faces of the cubes at once, it's amazing how much faster it is. I'm going to do something similar with foliage and some other effects, what's nice about Irrlicht is that I do not have to create my own model loaders, I've been using OpenGL for a while and I made a MD2 loader...and after I finally got it working I decided I wasn't going to do it again. The only reason I stuck with OpenGL is that I can do so much with the render function (draw things in bulk).

Funny thing is that everyone says "You want a insertnamehere loader? Google it, they are everywhere!"...which is not a complete lie, but I've been trying for a week trying to get one of the many model loaders I've found to work properly... It seems as if some things work and others do not, I really only wanted something with basic animation ability. Problem is I'm going to use Blender, which (in the new versions) rules out MD2...so I'm still working on how I'm going to animate stuff...but at least I won't have to make a model loader...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: OpenGL Main Loop

Post by hybrid »

You have to call the drawVertexPrimitiveList inside the render loop.
g0bl1n
Posts: 63
Joined: Thu Feb 21, 2008 8:45 am

Re: OpenGL Main Loop

Post by g0bl1n »

I changed my vertices to the S3DVertex type, but I'm having trouble with the normal vectors, mainly because I've never had to use them to draw anything standard (aka just to draw a simple shape with no translations/other transformations) in OpenGL. I figured at first the normal vector would be the "up" vector, but I've tried a bunch of different things, none worked thus far. I don't have to calculate a normal vector (e.g. a parrallel vector) to draw a simple quad do I?

Vertex Declaration

Code: Select all

float size=100;
irr::video::S3DVertex verts[4]=
{
        irr::video::S3DVertex(-size, size,0, 0,0,1, irr::video::SColor(255,0,0,0),0,0),
        irr::video::S3DVertex( size, size,0, 0,0,1, irr::video::SColor(255,0,0,0),0,0),
        irr::video::S3DVertex( size,-size,0, 0,0,1, irr::video::SColor(255,0,0,0),0,0),
        irr::video::S3DVertex(-size,-size,0, 0,0,1, irr::video::SColor(255,0,0,0),0,0),
};
Main Loop (Render Loop):

Code: Select all

device->getVideoDriver()->beginScene(true,true,irr::video::SColor(255,100,101,140));
        irr::video::SMaterial material;
        material.BackfaceCulling=false;
        material.EmissiveColor.set(0xffFFff);
        device->getVideoDriver()->setMaterial(material);
                device->getVideoDriver()->setTransform(irr::video::ETS_WORLD,irr::core::matrix4());
                device->getVideoDriver()->drawVertexPrimitiveList(verts,4,prims,4,irr::video::EVT_STANDARD,irr::scene::EPT_QUADS);
        device->getSceneManager()->drawAll();
device->getVideoDriver()->endScene();
 
Edit:
To my amazment this works:
Main Loop (Render Loop):

Code: Select all

device->getVideoDriver()->beginScene(true,true,irr::video::SColor(255,100,101,140));
        glDisable(GL_CULL_FACE);
        glBegin(GL_QUADS);
        float size=100;
        glVertex3f(-size,size,0);
        glVertex3f(size,size,0);
        glVertex3f(size,-size,0);
        glVertex3f(-size,-size,0);
        glEnd();
        device->getSceneManager()->drawAll();
device->getVideoDriver()->endScene();
 
But it would still be nice to know how to do this the Irrlicht way, that way I can using Irrlicht's lighting instead of making my own system!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: OpenGL Main Loop

Post by hybrid »

It shoudl be 4, prims, 1, but besides that everything seems good. Do you have a light? Else better disable lighting in the material
g0bl1n
Posts: 63
Joined: Thu Feb 21, 2008 8:45 am

Re: OpenGL Main Loop

Post by g0bl1n »

Alright I figured it out, I wasn't using the right sized primatives, for an int array I need to use irr::video::EIT_32BIT, or use short array and irr::video::EIT_16BIT (which is the default).

Declarations:

Code: Select all

short prims[8]=
{
        0,1,2,3,
        4,5,6,7
};
 
float size=10;
S3DVertex verts[8]=
{
        S3DVertex(-size, size,0, 0,0,0,SColor(255,255,0,0),0,1),
        S3DVertex( size, size,0, 0,0,0,SColor(255,0,255,0),1,1),
        S3DVertex( size,-size,0, 0,0,0,SColor(255,0,255,0),1,0),
        S3DVertex(-size,-size,0, 0,0,0,SColor(255,255,0,0),0,0),
 
        S3DVertex(-size,0, size, 0,0,0,SColor(255,255,255,255),0,1),
        S3DVertex( size,0, size, 0,0,0,SColor(255,255,255,255),1,1),
        S3DVertex( size,0,-size, 0,0,0,SColor(255,255,255,255),1,0),
        S3DVertex(-size,0,-size, 0,0,0,SColor(255,255,255,255),0,0),
};
Render Loop:

Code: Select all

irr::video::SMaterial material;
material.BackfaceCulling=false;
material.Lighting=false;
material.EmissiveColor.set(0xffFFff);
device->getVideoDriver()->setMaterial(material);
device->getVideoDriver()->setTransform(irr::video::ETS_WORLD,irr::core::matrix4());
device->getVideoDriver()->drawVertexPrimitiveList(verts,8,prims,2,irr::video::EVT_STANDARD,irr::scene::EPT_QUADS,irr::video::EIT_16BIT);
Thanks all for help!
Post Reply