Jump to content

Rotating a texture?


Chiblue
 Share

Recommended Posts

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?

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

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)

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

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

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

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??

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

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..

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...