OpenGL Main Loop [SOLVED]
OpenGL Main Loop [SOLVED]
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.
Re: OpenGL Main Loop
check irr::video::IVideoDriver::drawVertexPrimitiveList in doc.
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
Re: OpenGL Main Loop
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:
Draw Code (in main loop):
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
};
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);
Re: OpenGL Main Loop
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?
I can't see the point in using Irrlicht for rendering but not using the render function. Are you just trying to learn OpenGL?
Re: OpenGL Main Loop
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...
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...
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: OpenGL Main Loop
You have to call the drawVertexPrimitiveList inside the render loop.
Re: OpenGL Main Loop
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
Main Loop (Render Loop):
Edit:
To my amazment this works:
Main Loop (Render Loop):
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!
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),
};
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();
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();
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: OpenGL Main Loop
It shoudl be 4, prims, 1, but besides that everything seems good. Do you have a light? Else better disable lighting in the material
Re: OpenGL Main Loop
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:
Render Loop:
Thanks all for help!
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),
};
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);