irrCg v0.8 (Initial) - CgFX (Texture States, MultiPass etc.)

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

Found the problem!!!!!!!

Declaration of OnSetConstants in Examples are incorrect :

Code: Select all

virtual void OnSetConstants( ICgServices* services,CGprogram Vertex,CGprogram Pixel,const irr::video::SMaterial& Material )                
note const declaration of Material!

Suspect this is the case in all other examples as well.

Asp
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Hi, Yes it's my fault. I forgot update examples. Now I see also linker error. I tested it with my modified Irrlicht version, so I didn't see it before. I will improve it soon.

@Update
I fixed all bugs and I send improved version of irrCg on SVN. Thanks asparagusx for report.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

Nadro - you are a star!

I thought I was going mad with all the problems and linker errors I received. I have now downloaded the latest SVN and it certainly works as expected.

In terms of shaders themselves. Are there any 'standard' Cg shaders and equivalent callbacks that you know of, or is in the process of development? I am looking at extending our existing materials library in our application with shader materials, based on Cg and irrCg - any information will be appreciated. I am a noob when it comes to shaders and need any assistance/advice provided.

Thanks again.

Asp
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Hi, I have got on TODO list create more materials and prebuild current examples to more useful for users, it will be out with v0.7.1 (final) but now I don't know when I will find some free time for it, but not faster than one month.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
bmwop
Posts: 11
Joined: Tue Jul 07, 2009 4:04 pm

Post by bmwop »

Now it seems quite linux-friendly :)

By the way IrrCg.cpp:143 has a warning.

I noticed that a texture material bug has been fixed, great, thanks! Linux builds fine. (i hope i can also test this on Windows tomorrow).
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Thanks bmwop for a report. I fixed it.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
bmwop
Posts: 11
Joined: Tue Jul 07, 2009 4:04 pm

Post by bmwop »

Hi Nadro,

i noticed some strange behaviour with D3D9 under Windows:
- my shadow (with shadow map) disappeared with the new irrcg. OpenGL works fine on both Win and Linux.
- if i change cgD3D9SetTextureParameter to cgD3D9SetTexture as it was before it appears again
- if i change the ManageTextureParameters to true i also have strange things: materials change their textures (sometimes they have the right one but in an other frame they have textures belong to some other material)

Any advice? Am i missed something? (But opengl is good.)
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

With v0.7 all works ok? Do You use texture registers in Your shader? eg.:

Code: Select all

sampler2D myTexture0 : register(s0);
sampler2D myTexture1 : register(s1);
instead of:

Code: Select all

sampler2D myTexture0;
sampler2D myTexture1;
I see that in Cg this is very important.

When ManageTextureParameters is turn ON, You can see artifacts, this is bug. Currently You should leave this option on "false" . I will improve it.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
bmwop
Posts: 11
Joined: Tue Jul 07, 2009 4:04 pm

Post by bmwop »

Nadro wrote:With v0.7 all works ok? Do You use texture registers in Your shader?
Yes and yes. I try to find out what's happening here. I will come back if i found something.
bmwop
Posts: 11
Joined: Tue Jul 07, 2009 4:04 pm

Post by bmwop »

bmwop wrote:
Nadro wrote:With v0.7 all works ok? Do You use texture registers in Your shader?
Yes and yes. I try to find out what's happening here. I will come back if i found something.
I think i have problem with textures that are not part of the material. So if i have an object i can set textures for its material (up to 4 by default in Irrlicht). In the OnSetConstants() function i use EnableTexture() function to give the texture to the shader, but i use this function also to give textures (like the shadowMap) to the shaders, that were not set in Irrlicht for this material.

Maybe this is the problem. The EnableTexture of the old IrrCg worked for both type of textures.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Old irrCg version has got bug in material renderer. If You don't use textures which are bind by Irrlicht (up to 8 in the latest SVN) You have to use setTexture instead of Enable texture for manual bind current texture by irrCg.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
bmwop
Posts: 11
Joined: Tue Jul 07, 2009 4:04 pm

Post by bmwop »

Nadro wrote:Old irrCg version has got bug in material renderer. If You don't use textures which are bind by Irrlicht (up to 8 in the latest SVN) You have to use setTexture instead of Enable texture for manual bind current texture by irrCg.
Yes, binding by irrlicht solved the problem, and i don't need the EnableTexture() anymore. Thanks!
offmonreal
Posts: 6
Joined: Sat Feb 09, 2008 7:12 am
Contact:

Post by offmonreal »

IrrCg will support the MinGW compiler?
The user not speaking GOOD on EN
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

offmonreal wrote:IrrCg will support the MinGW compiler?
You can always compile irrCg with MinGW.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
ecsos
Posts: 30
Joined: Mon Feb 04, 2008 8:02 am

Post by ecsos »

i got this to compile on mac os x (and run all of the examples), but I couldn't get it to work using code::blocks. i ended up using the mac os x irrlicht xcode project and just added the irrcg source files to it, and fixed any u32/s32 related errors that the trunk svn of irrlicht would cause.

IrrCgExtensionHandler.h changes:
you can include <OpenGL/gl.h> for mac instead of GL/gl.h but when it's in the irrlicht project you don't need any of those gl includes.

I had to comment out everything to do with pGlActiveTextureARB in IrrCgExtensionHandler.h when compiling for mac, but...
I don't know opengl, so i have to ask, is it okay to use glActiveTextureARB(texture) in the IrrCgExtensionHandler.h extGlActiveTexture function ? (instead of pGlActiveTextureARB, when compiling for mac). I read something about this but not sure, though it seems to work fine..

IrrCg.cpp changes:
Also, at least for svn trunk irrlicht, had to alter IrrCg.cpp and remove the setActiveTexture function

all of the demos look the same as my old windows binaries do, though the elephant always complains about missing Elephant.mtl which doesn't exist anyways.

---------------

Code: Select all

Index: include/IrrCgExtensionHandler.h
===================================================================
--- include/IrrCgExtensionHandler.h	(revision 7)
+++ include/IrrCgExtensionHandler.h	(working copy)
@@ -6,8 +6,12 @@
 #define __IRR_CG_EXTENSION_HANDLER_H_INCLUDED__
 
 #ifdef IrrCgOGL
-
+
+#ifdef IrrMacOSX
+#include <OpenGL/gl.h>
+#else
 #include <GL/gl.h>
+#endif
 
 #ifdef IrrCgWin32
 #include <windows.h>
@@ -23,7 +27,10 @@
     class IrrCgExtensionHandler
     {
     public:
-        IrrCgExtensionHandler() : pGlActiveTextureARB(0)
+        IrrCgExtensionHandler()
+        #ifndef IrrMacOSX
+         : pGlActiveTextureARB(0)
+        #endif
         {
             #ifdef IrrCgWin32
             pGlActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB");
@@ -37,13 +44,19 @@
         ~IrrCgExtensionHandler(){};
 
         inline void extGlActiveTexture(GLenum texture)
-        {
+        {
+            #ifdef IrrMacOSX
+            glActiveTextureARB(texture);
+            #else
             if (pGlActiveTextureARB)
-            pGlActiveTextureARB(texture);
+            pGlActiveTextureARB(texture);
+            #endif
         }
 
-    private:
-		PFNGLACTIVETEXTUREARBPROC pGlActiveTextureARB;
+    private:
+    #ifndef IrrMacOSX
+		PFNGLACTIVETEXTUREARBPROC pGlActiveTextureARB;
+    #endif
     };
 }

Code: Select all

Index: source/IrrCg.cpp
===================================================================
--- source/IrrCg.cpp	(revision 7)
+++ source/IrrCg.cpp	(working copy)
@@ -1,21 +1,31 @@
 // Copyright (C) 2007-2009 Patryk Nadrowski
 // This file is part of the "irrCg".
 // For conditions of distribution and use, see copyright notice in License.txt
-
+#include "IrrCompileConfig.h"
 // You have to define it, if You compile on Windows. Require Windows PlatformSDK.
+#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
 #define IrrCgWin32
-
+#endif
 // You have to define it, if You compile on Linux.
-// #define IrrCgLinux
+#if defined(_IRR_LINUX_PLATFORM_)
+#define IrrCgLinux
+#endif
 
+#if defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
+#define IrrMacOSX
+#endif
 // You have to define it, if You use Irrlicht Linux Shared Library (*.so)
 // #define IrrCgSharedLib
 
 // You have to define it, if You need Cg support for Direct3D program. Require DirectX SDK.
+#if defined(_IRR_COMPILE_WITH_DIRECT3D_9_)
 #define IrrCgD3D9
+#endif
 
 // You have to define it, if You need Cg support for OpenGL program.
+#if defined(_IRR_COMPILE_WITH_OPENGL_)
 #define IrrCgOGL
+#endif
 
 // Irrlicht Header
 #include "irrlicht.h"
@@ -64,47 +74,9 @@
 #ifndef IrrCgSharedLib
 
 // Get OpenGL Texture Name. Like standard Irrlicht getOpenGLTextureName().
-#ifdef IrrCgOGL
-GLuint irr::video::COpenGLTexture::getOpenGLTextureName() const
-{
-    return TextureName;
-}
 
 #if IRRLICHT_VERSION_MINOR > 5
-// Set OpenGL Active Texture. Like standard Irrlicht OpenGL setActiveTexture().
-bool irr::video::COpenGLDriver::setActiveTexture(u32 stage, const video::ITexture* texture)
-{
-	if (stage >= MaxTextureUnits)
-		return false;
 
-	if (CurrentTexture[stage]==texture)
-		return true;
-
-	if (MultiTextureExtension)
-		extGlActiveTexture(GL_TEXTURE0_ARB + stage);
-
-	CurrentTexture[stage]=texture;
-
-	if (!texture)
-	{
-		glDisable(GL_TEXTURE_2D);
-		return true;
-	}
-	else
-	{
-		if (texture->getDriverType() != EDT_OPENGL)
-		{
-			glDisable(GL_TEXTURE_2D);
-			printf("Fatal Error: Tried to set a texture not owned by this driver.");
-			return false;
-		}
-
-		glEnable(GL_TEXTURE_2D);
-		glBindTexture(GL_TEXTURE_2D,
-			static_cast<const COpenGLTexture*>(texture)->getOpenGLTextureName());
-	}
-	return true;
-}
 #else
 // Set OpenGL Texture. Like standard Irrlicht OpenGL setTexture().
 bool irr::video::COpenGLDriver::setTexture(u32 stage, const video::ITexture* texture)
@@ -152,7 +124,6 @@
 }
 #endif
 
-#endif
 
 namespace IrrCg
 {
Using those two diffs, you can add the source and header files to the libirrlicht.a target in the MacOSX Xcode project, add the Cg.framework (download from nvidia site, if you have trouble find the gzipped file in the installer app they provide and manually install it)

i'd like some explanation on the functions I removed to make this work for the SVN but don't have time to look myself. but this works for mac it seems when you replace the HelloWorld project with Nadro's Basic Lighting, and copy the cg and media folder contents to their respective places.

i've also got project files for standalone IrrCg static library and a BasicLighting project that uses it and the irrlicht framework for mac os x which compiles and runs as long as there aren't console options to choose from.
Post Reply