Chiblue Posted February 17, 2010 Share Posted February 17, 2010 I have a texture or an arrow that I am drawing on to the screen, and based upon specific keyboard inputs I want to rotate it to point in a specific rotation, i.e. up, left, right and down, and any possible orientation between them, short of creating multiple textures for each rotation, how can I rotate the image and use the DrawImage function to display it, or am I going to have to drop into the opengl functions to do this? Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Masterxilo Posted February 17, 2010 Share Posted February 17, 2010 Yes, you'll have to use opengl. It's not difficult to use the opengl functions. Another way would be to use a textured plane entity in another world and render that world on top of the other things. Quote Hurricane-Eye Entertainment - Site, blog. Link to comment Share on other sites More sharing options...
Rick Posted February 17, 2010 Share Posted February 17, 2010 Another way would be to use a textured plane entity in another world and render that world on top of the other things. This might be a good option for you Chiblue. If you aren't familiar with worlds and how they work, everything you create goes inside a world. So you can create a world, set it to active, then create these planes and such and position them at the given distance to the camera, which the world could have it's own camera also if I remember correctly. Now in that world you can make these textured planes always face the camera and move the camera to get the right closeness that looks good. I believe you then have to make it so the camera doesn't clear and then you can render that world on top of your game world to get the user interface. This does create a nice separation, but I'm not sure how mouse input works with that. Max probably knows. Quote Link to comment Share on other sites More sharing options...
Chiblue Posted February 17, 2010 Author Share Posted February 17, 2010 Wow, I have enough problems dealing with the realities of one world... B) Just as a side is that how you got your 2D images on the game screen you posted in the Gallery, becuase that is exactly the look I want, but with a rotating arrow, I may try what you suggest as it would be a fun exercise, whether or not it does what I want, I may even make the image a model and rotate that.. that may look better... I think I have the OpenGL function ready to test (well compiled, probably crash my system.. ) Thanks for the help... Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Rick Posted February 17, 2010 Share Posted February 17, 2010 I used 2D images and DrawImage(). I don't require any sort of rotation. If you get the rotation working I would be interested in how you got it working. Quote Link to comment Share on other sites More sharing options...
Chiblue Posted February 18, 2010 Author Share Posted February 18, 2010 Well I got it working with one exception, loading the texturew as a DDS. This requires some effort based upon what I have read.. but actually doing the "plane" and rotating it is relatively simple, just the opengl coordinate system takes a litte getting used to.. void glStart2D(TScene &scene) { glPushMatrix(); glMatrixMode (GL_PROJECTION); glLoadIdentity(); glOrtho(0, scene.sx, scene.sy, 0, 0, 1); } void glEnd2D() { glPopMatrix(); } ... the code to display and rotate is... glStart2D(scene); glEnable( GL_TEXTURE_2D ); glBindTexture(GL_TEXTURE_2D, this->roseimage); // have to translate the rotational origin to the center of the plane glTranslatef(size.X/2,size.Y/2,0.0); // rotate it by angle required.. glRotatef(zrotation,0.0,0.0,1.0); // reset the rotation origin.. glTranslatef(0-size.X/2,0-size.Y/2,0.0); // build the plane at 0,0... by size x and y glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2i(0, 0); glTexCoord2i(0, size.Y); glVertex2i(0, size.Y); glTexCoord2i(size.X, size.Y); glVertex2i(size.X, size.Y); glTexCoord2i(size.X, 0); glVertex2i(size.X, 0); glEnd(); glEnd2D(); As you can see in the attached image the box is rotating with the player, but now I need to get my DDS images loaded on to it.... which I have worked out how to do but like I said I need to work through loading a DDS image into opengl... maybe Josh can give me a pointer.. B) Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Masterxilo Posted February 18, 2010 Share Posted February 18, 2010 You can use the textures loaded by the engine. I'll quickly add how to do this to my wiki article. Or better I add a "Page"/"Resource"/Tutorial on how to use OpenGl for drawing. Quote Hurricane-Eye Entertainment - Site, blog. Link to comment Share on other sites More sharing options...
Chiblue Posted February 18, 2010 Author Share Posted February 18, 2010 You can use the textures loaded by the engine. I'll quickly add how to do this to my wiki article. Or better I add a "Page"/"Resource"/Tutorial on how to use OpenGl for drawing. Either would be very much apprpeciated, problem is 2 fold understanding the initialization for 2D objects which based on my tests I had to use GL_PROJECTION, the coordinate system for 2D and the internal pixel coordinate system, finally loading and applying DDS textures... The first 2 I managed to work around, although I think I did something wrong in the glOrtho function because when I load my 2D object I get very strange lighting affects... But as I said anything you can provide in the way of tutorial or advice would be very helpful, thanks Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Masterxilo Posted February 18, 2010 Share Posted February 18, 2010 Just finished the tutorial/example article: Using OpenGL for drawing Quote Hurricane-Eye Entertainment - Site, blog. Link to comment Share on other sites More sharing options...
Chiblue Posted February 18, 2010 Author Share Posted February 18, 2010 Thank you... I appreciate the effort.. nice review.. Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Chiblue Posted February 19, 2010 Author Share Posted February 19, 2010 Just finished the tutorial/example article: Using OpenGL for drawing I cannot get this to work, I copied your code and that works fine... I applied your code to my project... the functions and include are as in your code... This is the code were I try to use the 2D and texture draw... leglBegin(); glColor4f(0.0f, 1.0f, 1.0f, 0.5f); glTranslatef(size.X/2,size.Y/2,,0.0f); glRotatef(zrotation,0.0f,0.0f,1.0f); glScalef(1.1f, 0.8f, 0.0f); leglBindTexture(this->roseimage); glBegin(GL_QUADS); glTexCoord2i(1,1); glVertex2i(0-size.X/2, 0-size.Y/2); glTexCoord2i(1,0); glVertex2i(0-size.X/2, size.Y/2); glTexCoord2i(0,0); glVertex2i(size.X/2, size.Y/2); glTexCoord2i(1,0); glVertex2i(size.X/2, 0-size.Y/2); glEnd(); glLoadIdentity(); leglBindTexture(NULL); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); leglEnd() I want the texture in the top left corner spinning... any thoughts? I get nothing on the screen?? I also pasted your code in and I get the line following the mouse but the GL_QUADS does not display?? Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Masterxilo Posted February 19, 2010 Share Posted February 19, 2010 Make sure this code is called after drawing everything 3D. Also make sure to set the back buffer as the current buffer AGAIN, after 3D drawing. Check the example. Quote Hurricane-Eye Entertainment - Site, blog. Link to comment Share on other sites More sharing options...
Chiblue Posted February 19, 2010 Author Share Posted February 19, 2010 Yes I did both of them... If I run my start and end code, with your texture function everything works... but if I use your start and end functions it seems like the co-ordinates are meesed up.. i.e. I get a white screen or a large white block... and I don't see the difference, this is my code.. void glStart2D(TScene &scene) { glPushMatrix(); glMatrixMode (GL_PROJECTION); glLoadIdentity(); glOrtho(0, scene.sx, scene.sy, 0, 0, 1); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Drawing color. glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } void glEnd2D() { glBindTexture(GL_TEXTURE_2D, NULL); glDisable(GL_TEXTURE_2D); glMatrixMode(GL_MODELVIEW); glPopMatrix(); // Undo changed settings. glDisable(GL_BLEND); glCullFace(GL_BACK); glDisable(GL_CULL_FACE); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } The main difference I see is that I have "glMatrixMode (GL_PROJECTION);" which if I set it to GL_MODELVIEW I do not get the images... I also use glOrtho not gluOrtho2D.. glStart2D(scene); glColor4f(0.0f, 0.0f, 0.0f, 0.5f); // have to translate the rotational origin to the center of the plane glTranslatef(size.X/2,size.Y/2,0.0); // rotate it by angle required.. glRotatef(zrotation,0.0,0.0,1.0); // reset the rotation origin.. glTranslatef(0-size.X/2,0-size.Y/2,0.0); // build the plane at 0,0... by size x and y glScalef(1.0f, 1.0f, 0.0f); glEnable(GL_TEXTURE_2D); BindTexture(this->roseimage, 0); // LE command. glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2i(0, 0); glTexCoord2i(0, 1); glVertex2i(0, size.Y); glTexCoord2i(1, 1); glVertex2i(size.X, size.Y); glTexCoord2i(1, 0); glVertex2i(size.X, 0); glEnd(); glEnd2D(); But using this start and end and the above code, everything works fine.. I did have a problem but I once I did a glDisable(GL_TEXTURE_2D); everything seems to work as I want it... I know this start and end do not support 3D drawing but I only need the 2D... I would still like to know what I am doing wrong.. Interestingly I created a new function will your tutorial code in it and using your start and end, when I called the function I still had the same problems... I should add that I am using a modified verion of Gamelib, which may or maynot be causing an issue.. Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Masterxilo Posted February 19, 2010 Share Posted February 19, 2010 Try using a different culling mode in the leglBegin() function (e.g. CULL_NONE). Can you show me a short example where those start/end functions work and mine not? I'd like to fix that. Quote Hurricane-Eye Entertainment - Site, blog. Link to comment Share on other sites More sharing options...
Chiblue Posted February 20, 2010 Author Share Posted February 20, 2010 If you use the demo you created and then try to use any 2D functions after the leglEnd you cannot... Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Masterxilo Posted February 20, 2010 Share Posted February 20, 2010 Thanks for telling me, I fixed this. Quote Hurricane-Eye Entertainment - Site, blog. Link to comment Share on other sites More sharing options...
Chiblue Posted February 20, 2010 Author Share Posted February 20, 2010 Works like a dream, thanks again for all your help... Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.