|
Hi,
I'm new to openGL programming. I'm trying to simulate motion and zooming in and out in an SimpleOpenGLControl from the Tao Framework. <so you="ll need to install the framework and put in a reference in Visual Studio to " tao=" in order to test my code">
I've just begun trying to move an object up and down, but i can't seem to get the object to move. i know i'm missing something but i can't figure it out. I think it has to do with loading the transformed coordinates into a new buffer and displaying the contents from the buffer... but i don't know how to do that.
Here's my code:
<br />
Imports Tao.OpenGl<br />
Imports Tao.Platform<br />
Imports Tao.FreeGlut<br />
<br />
Public Class frmMainWin<br />
<br />
Dim xTrans, yTrans, zTrans As Single<br />
<br />
Private Sub frmMainWin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
myGlWindow.InitializeContexts()<br />
myGlWindow.AutoSwapBuffers = True<br />
<br />
'init glwindow<br />
Gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F)<br />
<br />
'Glu.gluLookAt(<br />
Gl.glViewport(0, 0, 400, 300)<br />
Gl.glMatrixMode(Gl.GL_PROJECTION)<br />
Gl.glLoadIdentity()<br />
<br />
Gl.glOrtho(0.0, 10.0, 0.0, 10.0, -10.0, 10.0)<br />
Gl.glMatrixMode(Gl.GL_MODELVIEW)<br />
Gl.glLoadIdentity()<br />
<br />
xTrans = 0<br />
yTrans = 0<br />
zTrans = 0<br />
<br />
End Sub<br />
<br />
Private Sub myGlWindow_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles myGlWindow.Paint<br />
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT)<br />
<br />
Gl.glColor3f(0.2F, 0.2F, 0.8F)<br />
<br />
'Gl.glTranslatef(0.0F, 0.0F, 0.0F)<br />
Gl.glTranslatef(xTrans, yTrans, zTrans)<br />
Gl.glBegin(Gl.GL_TRIANGLES) 'Draw a triangle<br />
Gl.glVertex3f(0.5F, 1.0F, 0.0F)<br />
Gl.glVertex3f(0.0F, 0.0F, 0.0F)<br />
Gl.glVertex3f(1.0F, 0.0F, 0.0F)<br />
Gl.glEnd()<br />
<br />
End Sub<br />
<br />
Private Sub cmdUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUp.Click<br />
'MsgBox("up")<br />
yTrans = yTrans + 1<br />
<br />
myGlWindow.SwapBuffers()<br />
<br />
End Sub<br />
End Class<br />
Any help would be greatly appreciated.
Thanks
|
|
|
|
|
Hi,
do you invalidate the control somehow when changing yTrans? Otherwise, you won't notice any change. Check whether the Paint method is called at all using the debugger.
EDIT:
2 more things:
1.) Handle the Resize-Event and do the following:
Sorry, this is C#, but I don't really have an idea about VB. I guess this will help anyway:
<br />
private bool initialized = false;<br />
<br />
protected override void OnResize(EventArgs e)<br />
{<br />
if (initialized)<br />
{<br />
MakeCurrent();<br />
<br />
Gl.glViewport(0, 0, Width, Height);<br />
Gl.glMatrixMode(Gl.GL_PROJECTION);<br />
Gl.glLoadIdentity();<br />
Gl.glOrtho(0.0, 10.0, 0.0, 10.0, -10.0, 10.0);<br />
Gl.glMatrixMode(Gl.GL_MODELVIEW);<br />
Gl.glLoadIdentity();<br />
}<br />
}<br />
Also, make sure xTrans is not negative.
Last, why do you call SwapBuffers(), although you set AutoSwapBuffers to true before?
Hope this helps,
Chris
"Obstacles are those frightening things you see when you take your Eyes off your aim"
- Henry Ford
Articles
Blog
modified on Sunday, February 24, 2008 4:35 PM
|
|
|
|
|
Thanks for the information. I'll handle the resize event in a few.
Just checking...Is there any fault in not handling it?
What do you mean by "invalidate the control?"
About the swapping buffers issue... i was working with trial and error to try and see why my code wasnt working...thats why both are there (by mistake). I've removed the swapbuffers() fn now.
The solution to my problem i found was to clear the buffer and do 'myGlWindow.refresh' just after the transformation calculations. Don't know why it worked...may be you could explain it to me...
|
|
|
|
|
As long as your window cannot be resized, you do not really have to handle the resize event, that is true. However, as it is basically no more code (because you can just move most of your inialization code into it), I consider it better.
When a control is invalidated, you force the control and its children to redraw. The Invalidate()-method and the Refresh()-method do exactly that (only the latter also forces immediate redraw). Both methods are implemented by Control. However, Tao's SimpleOpenGlControl also offers a Draw()-method.
It's implementation is rather simple:
<br />
public void Draw() {<br />
this.Invalidate();<br />
}<br />
So it is essentially all the same thing! I suggest, however, to use the Draw()-method because future releases of the control might behave differently.
"Obstacles are those frightening things you see when you take your Eyes off your aim"
- Henry Ford
Articles
Blog
|
|
|
|
|
Thanks for the information. iv;e taken it into consideration and now i'm using the Draw() method ... and handling resizing.
Now i have another problem, which i think is related, coz i'm convinced that there's fundamentally something wrong with my code.
Let me try explain it. I have objects drawn into the SimpleOpenGL control onClick of different buttons, but the problem is everytime i click on a button to draw (add) a new object... the previous one disappears. might you know what the problem is?
Then another thing. I'd like to put text into the control. Could you point me in the right direction to do this.
I read some other guys post about doing it in C# (somewhere near this one)... but i couldnt find some GDITexFont function or sth like that.
Your help is highly valued and appreciated.
|
|
|
|
|
Hi,
from what you say I guess you don't really have a rendering-loop. See, your OpenGL image is drawn this way:
1. Clear screen (glClear(), etc.)
2. Draw allvisible objects in a certain order (lots of code)
3. Wait until OpenGL finished drawing (glFlush())
4. Swap front/back buffer to make the newly drawn objects visible (SwapBuffers())
So you have to remember a list of objects you want to draw. When one of your buttons is clicked, it should do sth like that:
myRenderList.Add(someObject);<br />
myOpenGLControl.Invalidate();
Note: Do NOT put any OpenGL commands in a button. You should have one and only one loop to do all the GL stuff!
Managing scene information (all objects, how to describe them, whether they are visible, etc.) is the hard part - the OpenGL commands are comparatively simple. (See the term 'scene graph' for more on that).
For text rendering, check NeHe's tutorial[^]. He presents three options. You might want to take a look at EaseSDK[^] to make things easier. It includes CeGUI, which supports not only text rendering, but real GUI elements such as buttons, scroll bars, etc.
Regards,
Chris
"Obstacles are those frightening things you see when you take your Eyes off your aim"
- Henry Ford
Articles
Blog
|
|
|
|
|
Greetings,
This is a newbie question. After I have installed Platform SDK 2003 on my XP, the compiler couldn't find "dshow.h". Then, I specifically picked up DirectShow from the SDK and installed it once again. It still couldn't find the header. I have searched the entire "Programe Files" folder and there is no "dshow.h". Where did it go?
Thanks,
Best,
Jun
|
|
|
|
|
After googling a bit, I seem to find a solution. Basically, I have to installed DirectX 9.0 Complete SDK, not other upgrades
Best,
Jun
|
|
|
|
|
Just curious, does Vista support MDX straight off, or does it have to be installed by the user?
|
|
|
|
|
I tried simple pixel-based skin detection using YCrCb color space, It worked fine but not for every Image, i guess it's becoz of the Thresholds (Cr,Cb)i have selected, Can any 1 tell me or refer me a fast algorithm becoz mine take lots of time in detection.....???
(Jameel)
|
|
|
|
|
Does anyone know how to read frame types from mpeg file?
I want to know if this frame is frame I, P or B
Some source code would be appreciated
Thanks
|
|
|
|
|
Does anybody know if DXSmith is a good wrapper for DirectX? Before I get too involved in implementing it, I mean. ?
|
|
|
|
|
hi all...
we are having a problm in our graduate project... in some phase in the project we needed to do meshing and triangulation for a person in a 2D image, wihch did succefully, thx God (now we have the vertices and triangles connecting them)... the next step is to prform texture mapping to our generated mesh... but after we set texture positions rendering the textured mesh... the output of texture mapping on my laptop wasn't properly drawn... although it's working properly at our supervisor's pc!! can anybody plz hlp us find a reason for this...
I'm sending a link having the original img and the output of the texture mapping on my laptop...
http://www.geocities.com/naroqueen/texture.html
we are using DirectX 9.0 in our texture mapping
|
|
|
|
|
Hi naroqueen
My first thought is that you're laptop sux. But perhaps a more thought out response is to ask what graphics card you have in your laptop. It's obviously approximating the texture, but not shading across primitives. The fact that it works on your supervisors PC suggests the code is good, and that it's your laptop that is the problem... So look at the differences in system and setup.
Gavin
|
|
|
|
|
sorry I don't know what do you mean by "you're laptop sux"...
secondly my display card is "Mobile Intel(R) 945GM Express Chipset Family" with graphics accelerator... my supervisor is working on wondows vista and I'm working on win xp media center..
may this affect our problem???
|
|
|
|
|
naroqueen wrote: Mobile Intel(R) 945GM
Ouch! This isn't a good card to use with intensive graphics. Generally, you want a bit more "oomph" than this.
|
|
|
|
|
naroqueen wrote: "Mobile Intel(R) 945GM Express Chipset Family"
These are know to have numerous issues even though intel tends to talk up their capabilities. If you can, get access to a hardy desktop machine with a solid dedicated gpu.
A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.
- -Lazarus Long
|
|
|
|
|
Hello,
I am new to DirectX.I didn't know about mesh picking in directx.
http://www.experts-exchange.com/Programming/Game/Q_21257512.html[^]
I referred above site.But this code not performing mesh picking.When I pick cube mesh using mouse, I need to highlight selected part triangle. How to do it? Please anyone help me. Thanks in advance.
|
|
|
|
|
Hi,
I'm just about to look at mesh-picking myself, so when i work it out, I'll post my findings.
Gavin.
|
|
|
|
|
Well i got the mesh-picking working. But as i understand it, if you want to pick primitives, you have to write your own collision code, accessing the meshes vert collection. I was going to work it out until i decided that it would be easier to just break my terrain down into meshes. So until i have a more specific need to pick primitives, you're on your own.
|
|
|
|
|
Hai Gavin W,
I tried mesh picking using airplane.x file.I render the airplane in wireframe(in drawmesh function).I call below MeshPick function in Mouse down function.
private bool MeshPick(Mesh mesh, int x, int y)
{
Vector3 v3Near = new Vector3(x, y, 0);
Vector3 v3Far = new Vector3(x, y, 1);
IntersectInformation closestHit;
v3Near.Unproject(device.Viewport,device.Transform.Projection,
device.Transform.View, device.Transform.World);
v3Far.Unproject(device.Viewport, device.Transform.Projection,device.Transform.View,device.Transform.World);
v3Far.Subtract(v3Near);
if (mesh.Intersect(v3Near, v3Far, out closestHit))
{
return true;
}
else
return false;
}
How to get intersected vertices and how to Highlight intersected triangle? I have no idea? Please help me.Thanks in advance.
|
|
|
|
|
Hai Gavin W,
I tried mesh picking using tiger.x file.I render the tiger in wireframe(in drawmesh function).I call below MeshPick function in Mouse down function.
private bool MeshPick(Mesh mesh, int x, int y)
{
Vector3 v3Near = new Vector3(x, y, 0);
Vector3 v3Far = new Vector3(x, y, 1);
IntersectInformation closestHit;
v3Near.Unproject(device.Viewport,device.Transform.Projection,
device.Transform.View, device.Transform.World);
v3Far.Unproject(device.Viewport, device.Transform.Projection,device.Transform.View,device.Transform.World);
v3Far.Subtract(v3Near);
if (mesh.Intersect(v3Near, v3Far, out closestHit))
{
return true;
}
else
return false;
}
How to get intersected vertices and how to Highlight intersected triangle? I have no idea? Please help me.Thanks in advance.
I am waiting for your answer.please help me.Thanks in advance.
|
|
|
|
|
Hai,
I am beginner in the development of filters using DirectX.We are in the process of developing codecs for mpeg2/mpeg4. May i know how we can find the stream type whether it is a audio stream, video stream or an data stream using FOURCC.
Thanks and Regards
Angeline
|
|
|
|
|
Hi Everyone
Can someone please assist me with the following : I have attached a basic paint app. The zooming works fine, but the rulers disappear when I scroll horizontally or vertically. I need the rulers to stay fixed like for example MS Word's rulers.
If anyone would be so kind as to take a look, I can mail you the app.
Thank you very much
|
|
|
|
|
Draw the rulers outside of the area you draw the image in, so they are not affected by the zoom action.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|