dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

ko es daru nepareizi?

 
dev.gamez.lv Forum Index -> OpenGL
View previous topic :: View next topic  
Author Message
Raymix



Joined: 01 Feb 2006
Posts: 35
Location: Aluksne

PostPosted: Wed Feb 01, 2006 2:27 am    Post subject: ko es daru nepareizi?

Rolling Eyes

sveiki visapkart, esmu jauninjais ieksh opengl un C++, bet meginu pamazam pamazam visu iezubrit... tatad
novilku vienu opengl32 wrapperi, bet mans speljuks uzreiz nokaras pie palaishanas. Ar pashu originalo wrappera kodu viss iet gludi, ka ari mans kods kompilejas ar 0 error 0 warning.

paskataties ludzu ko daru nepareizi un ko esmu piemirsis:
paldies jau ieprieksh

opengl32.cpp originalais
Code:

//////////////
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include <math.h>
#include "opengl32.h"
/////////////
func_glEnable_t   orig_glEnable;
////////////
void sys_glEnable (GLenum cap)
{
if(!(mode==GL_TRIANGLE_STRIP||mode==GL_TRIANGLE_FAN))
 {
glDisable(GL_DEPTH_TEST);
 }
else
 {
glEnable(GL_DEPTH_TEST);
 }

   {
   (*orig_glEnable) (cap);
   }
}
////////////



opengl32.h originalais
Code:

////////////
typedef void ( *func_glBegin_t) (GLenum mode);
////////////
typedef void ( *func_glEnable_t) (GLenum cap);
/////////////
extern func_glEnable_t   orig_glEnable;
///////////



tatad,, shis ir kods ko es izveidoju ar ceribu ka aizies,, kodu atpazina, bet nokaaraas:

opengl32.cpp (manis modificets)
Code:

/////////
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include <math.h>
#include "opengl32.h"
/////////
void __stdcall NEWglBegin( GLenum mode )
{
if(mode == GL_TRIANGLE_STRIP || mode == GL_TRIANGLE_FAN)

{
gfxDisableDepthTest;
}
else
{
gfxEnableDepthTest;
}

{
glBegin(mode);
}
}






opengl32.h (manis modificets)
Code:

/////////
typedef void ( *func_glBegin_t) (GLenum mode);
////////////
typedef void ( *func_glEnable_t) (GLenum cap);
/////////////
extern func_glEnable_t   orig_glEnable;
///////////
typedef void ( *func_gfxEnableDepthTest_t) (void);
typedef void ( *func_gfxDisableDepthTest_t) (void);
extern func_gfxEnableDepthTest_t   orig_gfxEnableDepthTest;
extern func_gfxDisableDepthTest_t   orig_gfxDisableDepthTest;
///////


man viss itka ir defineets, bet tapat neiet :/
shitais kods ir no manaspeljuka sdk: (cpp nepastav)

Gfxwrapper.h (originalais,,, izmantoju ka resursu, lai uzzinatu kadus parametrus spele izmanto)
Code:

#pragma once


enum GfxBlend
{
  GFX_ONE         = 21,
  GFX_ZERO        = 22,
  GFX_SRC_COLOR    = 23,
  GFX_INV_SRC_COLOR = 24,
  GFX_DST_COLOR    = 25,
  GFX_INV_DST_COLOR = 26,
  GFX_SRC_ALPHA    = 27,
  GFX_INV_SRC_ALPHA = 28,
};

enum GfxComp
{
  GFX_NEVER       = 41,
  GFX_LESS        = 42,
  GFX_LESS_EQUAL   = 43,
  GFX_EQUAL       = 44,
  GFX_NOT_EQUAL    = 45,
  GFX_GREATER_EQUAL = 46,
  GFX_GREATER      = 47,
  GFX_ALWAYS      = 48,
};
 
enum GfxFace
{
  GFX_NONE  = 61,
  GFX_FRONT = 62,
  GFX_BACK  = 63,
  GFX_CW   = 64,
  GFX_CCW   = 65,
};

enum GfxMatrixType
{
  GFX_VIEW      = 71,
  GFX_PROJECTION = 72,
};

enum GfxWrap
{
  GFX_REPEAT = 81,
  GFX_CLAMP  = 82,
};

enum GfxPolyMode
{
  GFX_FILL  = 91,
  GFX_LINE  = 92,
  GFX_POINT = 93,
};


// functions initialization for OGL, D3D or NONE (dummy)
extern void GFX_SetFunctionPointers( INDEX iAPI);


// enable operations
extern void (*gfxEnableDepthWrite)(void);
extern void (*gfxEnableDepthBias)(void);
extern void (*gfxEnableDepthTest)(void);
extern void (*gfxEnableAlphaTest)(void);
extern void (*gfxEnableBlend)(void);
extern void (*gfxEnableDither)(void);
extern void (*gfxEnableTexture)(void);
extern void (*gfxEnableClipping)(void);
extern void (*gfxEnableClipPlane)(void);

// disable operations
extern void (*gfxDisableDepthWrite)(void);
extern void (*gfxDisableDepthBias)(void);
extern void (*gfxDisableDepthTest)(void);
extern void (*gfxDisableAlphaTest)(void);
extern void (*gfxDisableBlend)(void);
extern void (*gfxDisableDither)(void);
extern void (*gfxDisableTexture)(void);
extern void (*gfxDisableClipping)(void);
extern void (*gfxDisableClipPlane)(void);

// set blending operations
extern void (*gfxBlendFunc)( GfxBlend eSrc, GfxBlend eDst);

// set depth buffer compare mode
extern void (*gfxDepthFunc)( GfxComp eFunc);
   
// set depth buffer range
extern void (*gfxDepthRange)( FLOAT fMin, FLOAT fMax);

// color mask control (use CT_RMASK, CT_GMASK, CT_BMASK, CT_AMASK to enable specific channels)
extern void (*gfxSetColorMask)( ULONG ulColorMask);
extern ULONG gfxGetColorMask(void);



// PROJECTIONS


// set face culling
extern void (*gfxCullFace)(  GfxFace eFace);
extern void (*gfxFrontFace)( GfxFace eFace);

// set custom clip plane (if NULL, disable it)
extern void (*gfxClipPlane)( const DOUBLE *pdPlane);

// set orthographic matrix
extern void (*gfxSetOrtho)( const FLOAT fLeft, const FLOAT fRight,
                     const FLOAT fTop,  const FLOAT fBottom,
                     const FLOAT fNear, const FLOAT fFar, const BOOL bSubPixelAdjust=FALSE);
// set frustrum matrix
extern void (*gfxSetFrustum)( const FLOAT fLeft, const FLOAT fRight,
                       const FLOAT fTop,  const FLOAT fBottom,
                       const FLOAT fNear, const FLOAT fFar);
// set view matrix
extern void (*gfxSetViewMatrix)( const FLOAT *pfMatrix=NULL);

// set texture matrix
extern void (*gfxSetTextureMatrix)( const FLOAT *pfMatrix=NULL);


// polygon mode (point, line or fill)
extern void (*gfxPolygonMode)( GfxPolyMode ePolyMode);



// TEXTURES


// texture settings (holds current states of texture quality, size and such)
struct TextureSettings {
public:
  //quailties
  INDEX ts_iNormQualityO;   
  INDEX ts_iNormQualityA;
  INDEX ts_iAnimQualityO;
  INDEX ts_iAnimQualityA;
  // sizes/forcing
  PIX ts_pixNormSize;
  PIX ts_pixAnimSize;
  // texture formats (set by OGL or D3D)
  ULONG ts_tfRGB8, ts_tfRGBA8;            // true color
  ULONG ts_tfRGB5, ts_tfRGBA4, ts_tfRGB5A1;  // high color
  ULONG ts_tfLA8,  ts_tfL8;              // grayscale
  ULONG ts_tfCRGB, ts_tfCRGBA;            // compressed formats
  // maximum texel-byte ratio for largest texture size
  INDEX ts_iMaxBytesPerTexel;
};
// singleton object for texture settings
extern struct TextureSettings TS;
// routine for updating texture settings from console variable
extern void UpdateTextureSettings(void);


// texture parameters for texture state changes
class CTexParams {
public:
  INDEX tp_iFilter;         // OpenGL texture mapping mode
  INDEX tp_iAnisotropy;      // texture degree of anisotropy (>=1.0f; 1.0=isotropic, default)
  BOOL  tp_bSingleMipmap;     // texture has only one mipmap
  GfxWrap tp_eWrapU, tp_eWrapV;  // wrapping states
  inline CTexParams(void) { Clear(); tp_bSingleMipmap = FALSE; };
  inline void Clear(void) { tp_iFilter = 00; tp_iAnisotropy = 0; tp_eWrapU = tp_eWrapV = (GfxWrap)NONE; };
  inline BOOL IsEqual( CTexParams tp) { return tp_iFilter==tp.tp_iFilter && tp_iAnisotropy==tp_iAnisotropy &&
                                    tp_eWrapU==tp.tp_eWrapU && tp_eWrapV==tp.tp_eWrapV; };
};

// get current texture filtering mode
extern void gfxGetTextureFiltering( INDEX &iFilterType, INDEX &iAnisotropyDegree);
// set texture filtering
extern void gfxSetTextureFiltering( INDEX &iFilterType, INDEX &iAnisotropyDegree);
// set texture LOD biasing
extern void gfxSetTextureBiasing( FLOAT &fLODBias);

// set texture wrapping mode
extern void (*gfxSetTextureWrapping)( enum GfxWrap eWrapU, enum GfxWrap eWrapV);

// set texture modulation mode (1X or 2X)
extern void (*gfxSetTextureModulation)( INDEX iScale);

// set texture unit as active
extern void gfxSetTextureUnit( INDEX iUnit);

// generate texture for API
extern void (*gfxGenerateTexture)( ULONG &ulTexObject);
// unbind texture from API
extern void (*gfxDeleteTexture)( ULONG &ulTexObject);


// set texture as current
//  - ulTexture = bind number for OGL, or *LPDIRECT3DTEXTURE8 for D3D (pointer to pointer!)
extern void gfxSetTexture( ULONG &ulTexObject, CTexParams &tpLocal);

// upload texture
// - ulTexture  = bind number for OGL, or LPDIRECT3DTEXTURE8 for D3D
// - pulTexture = pointer to texture in 32-bit R,G,B,A format (in that byte order)
// - ulFormat   = format in which the texture will be stored in accelerator's (or driver's) memory
// - bNoDiscard = no need to discard old texture (for OGL, this is like "use SubImage")
extern void gfxUploadTexture( ULONG *pulTexture, PIX pixWidth, PIX pixHeight, ULONG ulFormat, BOOL bNoDiscard);

// returns size of uploaded texture
extern SLONG gfxGetTextureSize( ULONG ulTexObject, BOOL bHasMipmaps=TRUE);

// returns bytes/pixels ratio for uploaded texture or texture format
extern INDEX gfxGetTexturePixRatio( ULONG ulTextureObject);
extern INDEX gfxGetFormatPixRatio(  ULONG ulTextureFormat);



// VERTEX ARRAYS

// prepare arrays for API
extern void (*gfxSetVertexArray)( GFXVertex4 *pvtx, INDEX ctVtx);
extern void (*gfxSetNormalArray)( GFXNormal *pnor);
extern void (*gfxSetTexCoordArray)( GFXTexCoord *ptex, BOOL b4=FALSE); // b4 = projective mapping (4 FLOATS)
extern void (*gfxSetColorArray)( GFXColor *pcol);


// draw prepared arrays
extern void (*gfxDrawElements)( INDEX ctElem, INDEX *pidx);

// set constant color for subsequent rendering (until 1st gfxSetColorArray() call!)
extern void (*gfxSetConstantColor)(COLOR col);
// color array usage control
extern void (*gfxEnableColorArray)(void);
extern void (*gfxDisableColorArray)(void);


// MISC

// converts internal formats among APIs
extern GLenum   AcquireFormat_OGL( D3DFORMAT eFormatD3D);
extern D3DFORMAT AcquireFormat_D3D( GLenum eFormatOGL);


// force finish of rendering queue
extern void (*gfxFinish)(void);


// compiled vertex array control
extern void (*gfxLockArrays)(void);
extern void gfxUnlockArrays(void);


// helper functions for drawing simple primitives thru drawelements

inline void gfxResetArrays(void)
{
  _avtxCommon.PopAll();
  _atexCommon.PopAll();
  _acolCommon.PopAll();
  _aiCommonElements.PopAll();
}
 
// render elements to screen buffer
extern void gfxFlushElements(void);
extern void gfxFlushQuads(void);


// check GFX errors only in debug builds
#ifndef NDEBUG
  extern void OGL_CheckError(void);
  extern void D3D_CheckError(HRESULT hr);
  #define OGL_CHECKERROR    OGL_CheckError();
  #define D3D_CHECKERROR(hr) D3D_CheckError(hr);
#else
  #define OGL_CHECKERROR    (void)(0);
  #define D3D_CHECKERROR(hr) (void)(0);
#endif



// ATI's TRUFORM support


// set truform parameters
extern void gfxSetTruform( const INDEX iLevel, BOOL bLinearNormals);
extern void (*gfxEnableTruform)( void);
extern void (*gfxDisableTruform)(void);


// set D3D vertex shader only if different than last time
extern void d3dSetVertexShader(DWORD dwHandle);


// macro for releasing D3D objects

#define D3DRELEASE(object,check) \
{ \
  INDEX ref; \
  do { \
   ref = (object)->Release(); \
   if(check) ASSERT(ref==0); \
  } while(ref>0);  \
  object = NONE; \
Back to top
View user's profile
GiGa
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 25 Sep 2003
Posts: 887

PostPosted: Wed Feb 01, 2006 8:55 am    Post subject:

Varbuut tas ir taapeec, ka tikko pamodos peec diezgan iisa miega... bet man kaut kaa gruuti saprast, ko tu meegjini te panaakt. Jebkuraa gadiijumaa:
Code:

{
gfxDisableDepthTest;
}
else
{
gfxEnableDepthTest;
}

vajag buut
Code:

{
gfxDisableDepthTest();
}
else
{
gfxEnableDepthTest();
}

ja gribi izsaukt taas funkcijas.
Back to top
View user's profile Send e-mail
elvman
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 09 Apr 2003
Posts: 1278
Location: Kuldiga

PostPosted: Wed Feb 01, 2006 3:13 pm    Post subject:

Nu bet protams.Tapec ka nav to iekavu, jau ari tev viss nokaras.(Tikai nesparotu,kapec tev Warnings bija 0.Buutu jaabuut - missing arguments (vai kaukaa tamliidziigi)).
_________________
long time; /* know C */
Back to top
View user's profile Visit poster's website
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Wed Feb 01, 2006 10:01 pm    Post subject:

Nekādam missing arguments nebija jābūt, jo tas uzrakstītais netika uztvers kā funkcija, bet kā parasts mainīgais. Un mainīgajam nevar būt nekādi argumenti.
Back to top
View user's profile Send e-mail
elvman
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 09 Apr 2003
Posts: 1278
Location: Kuldiga

PostPosted: Wed Feb 01, 2006 10:22 pm    Post subject:

Kaada jeega tev uzrakstiit vienkaarshi mainiigo,ja tu vinjam neuzdod nekaadu veertiibu?

Tas buutu tas pats,ja es rakstiitu:
Code:
int nStikls;
nStikls;


Manupraat tai jaabuut funkcijai (neesmu iedziljinaajies kodaa).
_________________
long time; /* know C */
Back to top
View user's profile Visit poster's website
GiGa
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 25 Sep 2003
Posts: 887

PostPosted: Wed Feb 01, 2006 10:45 pm    Post subject:

elvman, neviens tev nemaisa taa rakstiit - tik jeegas nekaadas :)

Un shajaa gadiijumaa ir tieshi kaa bubu saka, jo ir tas ir pointers uz funkciju:
Code:

extern void (*gfxDisableDepthTest)(void);


man gan tagad uzreiz nenaak praataa, kaapeec ja vinsh dara vienkaarshi:
Code:

gfxDisableDepthTest;

kaapeec buutu jaakaraas? vai tad tas nav vienkaarshi "dabuut gfxDisableDepthTest veertiibu un .. nedariit ar to neko"? kaads var paskaidrot, kaapeec tam buutu jaanokaraas? man izskataas, ka probleema ir kaut kur citur aarpus dotaa koda - varbuut to arii izraisa shito funkciju neizsaukshana, bet tieshi uz taam rindinjaam jau nevajadzeetu pakaarties, ne?
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Wed Feb 01, 2006 10:48 pm    Post subject:

Kļūda noteikti ir kautkur citur. Šāda rindiņa nevar kārties (nu vismaz nevajadzētu, cik zinu :)
Back to top
View user's profile Send e-mail
elvman
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 09 Apr 2003
Posts: 1278
Location: Kuldiga

PostPosted: Wed Feb 01, 2006 10:55 pm    Post subject:

Nee.Tam nebuutu jaanokaraas (tiko izmeegjinaaju uztaisiit funkciju un izsaukt to bez () ).Man laikam atminja no kaukurienes bija uzradusies informacija ka tam butu janokaras (manlieks ka man pasham ir bijis kad nokaras,bet varbut es kljudos).

Taatad turpinam mekleet kljuudu...
_________________
long time; /* know C */
Back to top
View user's profile Visit poster's website
Raymix



Joined: 01 Feb 2006
Posts: 35
Location: Aluksne

PostPosted: Fri Feb 03, 2006 1:04 am    Post subject:

kluda ir vienkarsha,, tai spelei, kurai meginu injektet sho dll ir pavisam savadaki komandu nosaukumi, neka manaa OGL wrapperii. Ideja vienkarshi bija, atrast caur SDK kaut mazako infu, ka, luuk shie parametri ir nosaukti un meginat parsaukt originalo kodu uz speles kodu, ta lai shamaa saprot. Bet kautko laizu garam visu laiku. Tadel ari pievienoju to GFXwrapper.h failu, jo tas naak no SDK

Bah, naksies laikam pariet uz D3D, jo shamo gan tik traki nemaina, bet infas par d3d8 funkciju nosaukumiem man ir loti maz :/
Back to top
View user's profile
Display posts from previous:   
dev.gamez.lv Forum Index -> OpenGL All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group