Help with dynamic drawing

edited March 2012 in Help request
First off, hello, as this is my first post on the forums.

I recently started developing with orx. I've read the tutorials and started writing my own code/configs. Begginings were not so pleasant, especially considering that I didn't touch C/C++ for a fairly long time and Java made me quite a lazy programmer ;)

I want to program a game for my MA thesis. The main hero of the game is a cat which is going to get fatter or thinner depending on the player's progress. To get the best result I want him to be drawn dynamically. I've searched the forums and found out that fairly recently the orxDisplay_Draw* functions have been added. The autocompletion in the Visual Studio didn't show it so I decided to get the newest version from the SVN. After updating the files it still didn't show up (is this normal for recently added things? I mean should the autocompletion automatically find functions etc. or is it required to be added manually?) so I just thought that I'll write it and see if it works. The project built successfuly but unfortunately my line was not drawn. Same thing for the circle. Dig through the forum a bit more and found out that I need to call the functions after orxRENDER_EVENT_START. Unfortunately that didn't help. I've tried calling draw functions after orxRENDER_EVENT_START and also commented out BackgroundColor field in the config. Still no success. Is there something I'm missing?
orxSTATUS orxFASTCALL TestField::Init(){	

	orxViewport_CreateFromConfig("Viewport");	
	//cat = orxObject_GetChild(orxObject_CreateFromConfig("Scene"));
	//orxConfig_Load("../conf/Kotek.ini");

	
	clock = orxClock_FindFirst(orx2F(-1.0f), orxCLOCK_TYPE_CORE);
	orxClock_Register(clock, update, orxNULL, orxMODULE_ID_MAIN, orxCLOCK_PRIORITY_NORMAL);
	
	//orxEvent_AddHandler(orxEVENT_TYPE_INPUT, handleInputEvent);
	orxEvent_AddHandler(orxEVENT_TYPE_RENDER, handleRenderEvent);
	
	return orxSTATUS_SUCCESS;
}
orxSTATUS orxFASTCALL TestField::handleRenderEvent(const orxEVENT *currentEvent){

	switch(currentEvent->eID){
		case orxRENDER_EVENT_START:
			{
				orxVECTOR vector1, vector2;
				orxVector_Set(&vector1, 0, 0, 0);
				orxVector_Set(&vector2, 640, 480, 0);
				orxDisplay_DrawLine(&vector1, &vector2, orx2RGBA(0xFF, 0xFF, 0xFF, 0x00));
				//orxLOG("Line drawn.");
				return orxSTATUS_FAILURE;				
			}
	}

	return orxSTATUS_SUCCESS;
}

Comments

  • edited March 2012
    Welcome to our little community xZPFxBarteq! :)

    I've just spent a few minutes looking this over and managed to get it to work:

    here's what I have written as my 'test' event handler:
    orxSTATUS orxFASTCALL StandAlone::EventHandler( const orxEVENT* currentEvent )
    {
    	switch( currentEvent->eType )
    	{
    		case orxEVENT_TYPE_RENDER:
            {
    			switch( currentEvent->eID )
    			{
    				case orxRENDER_EVENT_STOP:
    				{
    					orxVECTOR vector1 = { 0, 0, 0 };
    					orxVECTOR vector2 = { 640, 480, 0 };
    					orxDisplay_DrawLine( &vector1, &vector2, orx2RGBA( 0xFF, 0xFF, 0xFF, 0xFF ) );
    					return orxSTATUS_FAILURE;
    				}
    			}
            }
    	}
    	return orxSTATUS_SUCCESS;
    }
    

    The main differences are that I render the line on the 'stop' event (to make sure it is drawn last) and I changed the Alpha value of your colour (0 = transparent, 255[0xFF] = fully opaque)

    Give that a go, and if you've any more questions, don't hesitate to ask! :)
  • edited March 2012
    I made a mistake in the first post, the second time I write orxRENDER_EVENT_START it meant to be the STOP event. So, that didn't work, but as you mentioned..

    ..I messed up with the alpha value! Thought it's value is passed as the first argument. The simplest things make the biggest headaches :) Thank you very much, now it works great.

    Maybe you know if I can complete the autocompletion (haha) with the new functions or is it just something that'll come with newer versions of orx?
  • edited March 2012
    The auto-complete worked fine for me; seems sometimes visual studio just doesn't like updating quickly: I find doing a build occasionally helps though, your mileage may vary of course! :D
  • edited March 2012
    Hi xZPFxBarteq and welcome here!

    Grey beat me to it, but my money would also be on the transparent alpha. :)

    As for the completion, that would be Visual Studio IntelliSense. You can ask it to regenerate its database but in my experience it's proven to be quite ineffective in some situations.
    It might also depend on the versions, I have completion for the draw functions on my vs2008.
  • edited March 2012
    I use 2010 for the record... (and plan to install the 2012 beta soon...ish) ^_^
  • edited March 2012
    Ahah, well, internet went down at the wrong moment. Just ignore my reply entirely. Glad it now works for you though. :)
  • edited March 2012
    Hi !

    Just in case, for auto-completion and syntax color, there's Visual Assist, a plugin for Visual Studio (2008 in my case).

    I can't use Visual Studio without it. Very great tool, never have any problems.
  • edited March 2012
    Visual Assist is a great tool but note that it's not free nor does it work with the free version of Visual Studio (aka. Visual Studio Express).
  • edited March 2012
    Exact, that's the problem :)
  • edited April 2012
    Is there a way to make functions draw on top of some objects and behind others?
  • jimjim
    edited April 2012
    I think this question is answered here
    https://forum.orx-project.org/discussion/3070#Comment_3076
  • edited April 2012
    That'll work for objects with textures defined in the config file. If I understood correctly draw functions work only when called before orxRENDER_EVENT_START (draw under every other object) or after orxRENDER_EVENT_STOP (draw in front of every other object).

    As almost all of my main character is drawn dynamically it is a serious problem for me.
  • edited April 2012
    Well actually all rendering calls should to be made after orxRENDER_EVENT_START and before orxRENDER_EVENT_STOP.

    Now the easiest way to draw at a given depth is to override an object's rendering. Well actually you don't have to override it, you can draw behind, on top or actually substitute your own drawing.
    The depth is controlled via the Z coordinate, as usual.

    There are two events sent: orxRENDER_OBJECT_START and orxRENDER_OBJECT_STOP.
    If you make your drawing calls when listening to the start event, it'll be displayed behind the object, if it's done when listening to the stop event, it'll be displayed on top of the object.
    If you want to override the object's redering, listen to orxRENDER_OBJECT_START, make your draw calls there and return orxSTATUS_FAILURE from the event handler: that'll tell orx not to do any regular rendering for that object.

    One thing to note: only objects that have a valid orxGRAPHIC attached to them are considered by the renderer. If you only need a placeholder graphic, one solution is to use the embedded "pixel" texture if you don't want to define an external one.

    Let me know if you need more details about the whole procedure!

    PS: You can also listen to the orxRENDER_VIEWPORT_START/orxRENDER_VIEWPORT_STOP events if you need to draw things before/after a viewport has been rendered.
Sign In or Register to comment.